package com.fone.player.play;

import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.support.v4.view.ViewPager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.OrientationEventListener;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.HorizontalScrollView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.astuetz.PagerSlidingTabStrip;
import com.fone.player.ApplicationManage;
import com.fone.player.R;
import com.fone.player.activity.BaseFragmentActivity;
import com.fone.player.activity.main.SplashActivity;
import com.fone.player.activity.personal.NetCollectionActivity;
import com.fone.player.activity.personal.PlayRecordFragment;
import com.fone.player.airone.AirOne;
import com.fone.player.airone.AirServerDevice;
import com.fone.player.bean.RecordData;
import com.fone.player.billing.impl.FonePayManager;
import com.fone.player.billing.util.FoneConstants;
import com.fone.player.client.CollectionRst;
import com.fone.player.client.DramaRst;
import com.fone.player.client.DramaRst.Cnt;
import com.fone.player.client.Error;
import com.fone.player.client.FlinkvideoRst;
import com.fone.player.client.LoginRst;
import com.fone.player.client.RcmdRst;
import com.fone.player.client.Reporter;
import com.fone.player.client.Request;
import com.fone.player.client.VgdetailRst;
import com.fone.player.client.VgdetailRst.From;
import com.fone.player.client.VgdetailRst.Froms;
import com.fone.player.client.XyzplaRst;
import com.fone.player.client.XyzplaRst.Dfnt;
import com.fone.player.constant.FoneConstant;
import com.fone.player.entity.CacheVideo;
import com.fone.player.entity.OfflineCache;
import com.fone.player.entity.PlayRecord;
import com.fone.player.play.LinkVideoEvent.LinkVideoFrom;
import com.fone.player.play.adapter.AirOneListAdapter.AirOneViewHolder;
import com.fone.player.play.adapter.FonePlayerAdapter;
import com.fone.player.play.adapter.FullRuleSeriesItemAdapter;
import com.fone.player.play.adapter.FullVideoRelatedAdapter;
import com.fone.player.play.adapter.GridSeriesTabItemAdapter;
import com.fone.player.play.adapter.LiveModeAdapter;
import com.fone.player.play.adapter.LocalVideoRelatedAdapter;
import com.fone.player.play.adapter.MenuRateAdapter;
import com.fone.player.play.adapter.MenuSubAdapter;
import com.fone.player.play.adapter.MenuSwithAdapter;
import com.fone.player.play.adapter.MenuTrackAdapter;
import com.fone.player.play.adapter.RuleGridCacheItemAdapter;
import com.fone.player.play.adapter.SeriesModeAdapter;
import com.fone.player.play.adapter.ShortModeAdapter;
import com.fone.player.play.adapter.SingleModeAdapter;
import com.fone.player.play.adapter.UnRuleListCacheItemAdapter;
import com.fone.player.play.adapter.UnRuleSeriesItemAdapter;
import com.fone.player.play.gesture.FoneOnGesture;
import com.fone.player.sns.ISNSShareManager;
import com.fone.player.sns.UserInfoManager;
import com.fone.player.sns.bean.SNSUserInfo;
import com.fone.player.sns.bean.ShareInfo;
import com.fone.player.sns.impl.SNSShareManager;
import com.fone.player.storage.SharedPreferenceModule;
import com.fone.player.storage.StorageModule;
import com.fone.player.util.ActivityQueue;
import com.fone.player.util.FoneUtil;
import com.fone.player.util.L;
import com.fone.player.util.ScreenUtil;
import com.fone.player.util.SystemUtil;
import com.fone.player.view.AutoFocusTextView;
import com.fone.player.view.ColorBallProgressView;
import com.fone.player.view.CustomAlertDialog;
import com.fone.player.view.EnhanceHorizontalScrollView;
import com.fone.player.view.FoneGestureOverlayView;
import com.fone.player.view.LegalNoticeDialog;
import com.fone.player.view.NoScrollGridView;
import com.fone.player.view.SelectSharePopwindow;
import com.fone.player.view.UpdateDialog;
import com.fone.player.view.VideoDefinitionPopupWindow;
import com.fone.player.view.VideoFromPopupWindow;
import com.letv.sdk.onehundredtv.video.BDVideoPartner;
import com.letv.sdk.onehundredtv.video.IVideo;
import com.letv.sdk.onehundredtv.video.LetvSdk;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import de.greenrobot.event.EventBus;

/**
 * 视频播放Activity
 * 
 * 
 * @author kongxiaojun
 * @date:2014-4-16 下午1:53:53
 * 
 */
public class FonePlayerActivity extends BaseFragmentActivity implements
		PlayerFrom {

	private static final int UPDATE_TIME_MESSAGE = 1024;
	/** 拖动进度条 */
	private SeekBar mSeekBar;
	/** 全屏拖动进度条 */
	private SeekBar mSeekBar_full;
	/** 播放按钮 */
	private Button btPlay, btPlayFull;
	/** 播放SurfaceView */
	private SurfaceView videoSurface;
	/** 显示视频信息的layout */
	private View infoLayout;
	/** 全屏播放按钮 */
	private ImageButton fullIB;
	/** 方向监听 */
	private OrientationEventListener mListener;
	/** 是否进行方向监听 */
	private boolean mReverse = false;
	/** log TAG */
	private static final String TAG = "FonePlayerActivity";
	/*** 清晰度保存的key */
	private static final String DEFINITION_KEY = "definition";
	/** airone 设备选择框 */
	private AirOneSelectPopupWindow mSelectAireOnePopupWindow = null;
	/** 此Activity实例 */
	public static WeakReference<FonePlayerActivity> FonePlayerActivityInstance;
	/** 捕获手势View */
	private FoneGestureOverlayView mPlayerGestureView;
	/** 播放控制 */
	private FonePlayerAdapter playerAdapter;
	/** 外部事件监听 */
	private PlayerExternalEventReceiver eventReceiver;
	/** Handler */
	private Handler mHandler;
	/** 视频信息区的tab */
	private PagerSlidingTabStrip tabs;
	/** 视频信息区滑动的ViewPager */
	private ViewPager pager;
	/** 全屏显示的layout */
	private View mFullLayout;
	/** 小屏标题栏 */
	private View mTitlebarSmall;
	/** 全屏右边的选集/推荐layout */
	private View mFullRightLayout;
	/** 推荐/选集内容layout */
	private View mFullRightSeriesRecommend;
	/** 推荐/剧集按钮 */
	private Button mFullRecommend, mFullSeries;
	/** 投放按钮 */
	private Button mBtAirone;
	/** 点击事件监听器 */
	private View.OnClickListener mClickListener;
	private Animation mRightInAnim, mRightOutAnim;
	/** 播放进度条更新线程 */
	private SeekBarThread mSeekBarThread;
	/** surfaceView 所在的layout */
	private RelativeLayout surfaceLayout;
	/** 全屏模式时右上角的more按钮 */
	private Button fullMore;
	/** 更多菜单layout */
	private View moreMenuLayout;
	/** 菜单子项 */
	private List<TextView> moreMenuItems = new ArrayList<TextView>();
	/** 二级菜单 3d的开关/音轨选择。。。 */
	private PopupWindow secondWindow;
	/** 菜单点击监听 */
	private OnClickListener mMenuListener;
	/** 最大音量，当前音量 */
	private int maxVolume, currentVolume;
	/** 当前播放位置 */
	private int currentPostion;
	/** 音量管理器 */
	private AudioManager audiomanage;
	/** 显示音量调节/亮度/进度 layout */
	private View genstureLayout;
	/** 音量/亮度layout */
	private View soundBrightLayout;
	/** 音量/亮度icon */
	private ImageView ivSoundBright;
	/** 音量/亮度值 */
	private TextView tvSoundBright;
	/** 进度值 */
	private TextView tvGestureProgress;
	/** 是否正在手势更改音量/亮度 */
	private boolean gestureChangeVolOrBright;
	/** 音量百分比 */
	private int volPercentage;
	/** 当前屏幕亮度 */
	private float currentBrightness;
	/** 是否正在手势条件进度 */
	private boolean gestureChangeProgress;
	/** 全屏时进度和总长度 */
	private TextView tvFullProgress, tvFullDuration, tvSmallProgress,
			tvSmallDuration;
	/** 小屏返回按钮和全屏返回按钮 */
	private Button btFullBack, btBackSmall;
	/** 是否锁定 */
	private boolean lock;
	/** 锁定按钮 */
	private Button btLock;
	/** 全屏标题栏，左边栏，右边栏，控制栏 */
	private View mFullTitleBar, mFullLeft, mFullRight, mFullContorlBar;
	/** 小屏的标题 */
	private TextView mTitleSmall;
	/** 全屏的标题 */
	private AutoFocusTextView mTitleFull;
	/** 清晰度 */
	private Button mFullDefinition;
	/** 自动隐藏控制按钮时间 */
	private int controlAutoHideTime = 5000;
	/** 下一部按钮 */
	private Button fullPlayerNext;
	/** 小屏页只能h5播放的背景 */
	private ImageView h5bg;
	/** 收藏按钮，缓存按钮，分享按钮 */
	private Button playerCollection, playerCache, playerShare;
	/** 视频缓存layout,规则剧集缓存layout，不规则剧集缓存layout */
	private View videoSeriesCacheLayout, videoSeriesCacheRuleLayout,
			videoSeriesCacheUnRuleLayout;
	/** 视频缓存规则显示时的分页GridView */
	private NoScrollGridView videoSeriesCachePager;
	/** 视频缓存规则显示时分集 GridView */
	private GridView ruleVideoSeriesCacheGridView;
	/** 视频缓存列表不规则显示时的ListView */
	private ListView unRuleVideoSeriesCacheList;
	/** 视频缓存列表规则显示时的分页Adapter */
	private GridSeriesTabItemAdapter videoSeriesCachePagerAdapter;
	/** 视频缓存列表规则显示时item adpater */
	private RuleGridCacheItemAdapter ruleGridSeriesCacheItemAdapter;
	/** 视频缓存列表不规则显示时item adpater */
	private UnRuleListCacheItemAdapter unRuleSeriesCacheItemAdapter;
	/** 取消缓存，缓存按钮 */
	private Button videoSeriesCacheCancel, videoSeriesCacheOk;
	/** 全屏播放相关视频ListView */
	private ListView fullPlayerLinkList;
	/** 全屏播放时规则剧集 Layout */
	private View fullPlayerRuleSeriesLayout;
	/*** 全屏播放时规则剧集分页GridView */
	private GridView ruleSeriesPagerGrid;
	/*** 规则剧集分页adapter */
	private GridSeriesTabItemAdapter ruleSeriesPagerAdapter;
	/** 规则剧集item adapter */
	private FullRuleSeriesItemAdapter ruleSeriesItemAdapter;
	/** 不规则剧集item adapter */
	private UnRuleSeriesItemAdapter unRuleSeriesItemAdapter;
	/*** 全屏播放时规则剧集itemGridView */
	private GridView ruleSeriesItemGrid;
	private View airOnePlayingLayout;
	/** 小屏底部控制区（seekbar和全屏按钮） */
	private View playSmallControlLayout;
	/** 从哪个页面打开的视频播放 */
	private int openFrom;
	/** 加载进度条 */
	private ColorBallProgressView requestProgress;
	private TextView loadingMessage;
	/** 来源layout */
	private View fromLayout;
	/** 来源icon */
	private ImageView fromIcon;
	/** 来源PopupWindow */
	private VideoFromPopupWindow fromWindow;
	/** 剧集模式 */
	private SeriesModeAdapter seriesModeAdapter;
	/** 直播模式 */
	private LiveModeAdapter liveModeAdapter;
	/** 段视频模式 */
	private ShortModeAdapter shortModeAdapter;
	/** 单片模式 */
	private SingleModeAdapter singleModeAdapter;
	/**
	 * 0-->非3d模式，1-->3D模式
	 */
	private static int current3D = 0;
	/**
	 * 当前字幕
	 */
	private int currentSub = 0;
	/**
	 * 当前音轨
	 */
	private int currentAudioChannel = 0;
	/** 显示歌词TextView */
	private TextView tvSubtitle;
	/** 打开播放器动作 */
	private PlayerAction action;
	/** 全屏关联推荐 */
	private FlinkvideoRst flinkvideoRst;
	/** 本地关联视频 */
	private RcmdRst rcmdRst;
	/** 全屏关联视频adapter */
	private FullVideoRelatedAdapter fvrAdapter;
	/*** 本地关联视频Adapter */
	private LocalVideoRelatedAdapter lvrAdapter;
	/**
	 * 清晰度类型，逗号分隔，例如： 1,2,3 表示同时存在标清、高清、超 清
	 */
	private String dfnt;
	/** 清晰度popupwindow */
	private VideoDefinitionPopupWindow definitionPopupWindow;
	/** 详情页URL */
	private String vgdetail;
	/** 剧集bean */
	private DramaRst seriesRst;
	/** 缓存bean */
	private DramaRst cacheRst;
	private String xyzplay;
	/** SurfaceView 是否创建 */
	private boolean surfaceCreated = false;
	private int cacheSelectedNumber = 0;
	private static final int SHOW_UPDATE_DAILOG = 998;// 防止CASE重复
	private int currentFromIndex = 0;
	/** 计时器取消标识符 */
	private boolean isCancel = false;
	/** 是否正在计时 */
	private boolean isTimeing = false;
	/** 当前解码方式 */
	private int currentDecoderMode;
	private String videoName;
	private DisplayImageOptions fromOptions;
	/** 缓存剧集加载进度 */
	private ColorBallProgressView cacheProgress;
	/** 视频详情 Rst */
	private VgdetailRst videoDetail;
	/** activity 是否停止 */
	private boolean stop = false;
	/*** 是否正在缓冲中 */
	private boolean buffering;
	/** 全屏规则剧集导航tab的横向滚动View **/
	private EnhanceHorizontalScrollView fullRuleSeriesPagerHorizontalSV;
	private boolean isAddingCache = false;
	/** 切换软解对话框 */
	private CustomAlertDialog playerDialog;
	private int replayTimes = 0;
	/**
	 * 正在请求视频信息
	 */
	private boolean requestVideoInfo = false;
	/**
	 * 加载对话框
	 */
	private Dialog loadingDialog;
	/**
	 * 电池电量接收者
	 */
	private BatteryReceiver batteryReceiver;
	/**
	 * 电池状态图标
	 */
	private ImageView batteryStatus;
	/**
	 * 全屏播放时间
	 */
	private TextView fullSystemTime;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		L.v(TAG,
				"FonePlayerActivity onCreate start "
						+ System.currentTimeMillis());
		super.onCreate(savedInstanceState);
		FonePlayerActivityInstance = new WeakReference<FonePlayerActivity>(this);
		setContentView(R.layout.fone_play);
		initViews();
		initAnimations();
		initClickListener();
		setClickListener();
		initHandler();
		initPlayerAdapter();
		initPlayerExternalEventReceiver();
		initOrientationEventListener();
		enableOrientationEventListener();
		initPlayerGestureListener();
		handleIntent(getIntent());
		AirOne.Start();
		initAudioAndBrightness();
		keepScreenOn();
		EventBus.getDefault().register(this);
		mListener.disable();
		initImageOption();
		initLetvSDK();
		initBatteryReceiver();
		startUpdateTime();
	}

	@Override
	protected void onStart() {
		super.onStart();

		// 暂停所有下载任务
		StorageModule.getInstance().pauseAllCache(false);
	}

	@Override
	protected void onResume() {
		super.onResume();
		stop = false;
		hasNewIntent = false;
		unlock();
		// if (playerAdapter != null && playerAdapter.isPause() &&
		// !playerAdapter.isAirOneMode()) {
		// playerAdapter.play();
		// }

		if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
			onChangedOrientation(getScreenOrientation());
		}
		if (!isTimeing) {
			initUpdate();
		}

	}

	private void unlock() {
		lock = false;
		btLock.setBackgroundResource(R.drawable.video_fullscreen_unlock_selector);
	}

	private void initImageOption() {
		fromOptions = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.source_knowun)
				.showImageForEmptyUri(R.drawable.source_knowun)
				.showImageOnFail(R.drawable.source_knowun).cacheInMemory(true)
				.cacheOnDisk(true).considerExifParams(true).build();
	}

	/**
	 * 保持屏幕常亮
	 * 
	 * @return void
	 * @throws
	 */
	private void keepScreenOn() {
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	}

	/**
	 * 初始化音量和亮度
	 * 
	 * @return void
	 * @throws
	 */
	private void initAudioAndBrightness() {
		audiomanage = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
		maxVolume = audiomanage.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		currentVolume = audiomanage.getStreamVolume(AudioManager.STREAM_MUSIC);
		volPercentage = (int) (((double) currentVolume / (double) maxVolume) * 100);
		try {
			currentBrightness = (float) Settings.System.getInt(
					getContentResolver(), Settings.System.SCREEN_BRIGHTNESS) / 255f;
		} catch (SettingNotFoundException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 设置点击监听器
	 * 
	 * @return void
	 * @throws
	 */
	private void setClickListener() {
		mFullRecommend.setOnClickListener(mClickListener);
		mFullSeries.setOnClickListener(mClickListener);
		mBtAirone.setOnClickListener(mClickListener);
		fullMore.setOnClickListener(mClickListener);
		btPlay.setOnClickListener(mClickListener);
		btPlayFull.setOnClickListener(mClickListener);
		btFullBack.setOnClickListener(mClickListener);
		btBackSmall.setOnClickListener(mClickListener);
		btLock.setOnClickListener(mClickListener);
		videoSurface.setOnClickListener(mClickListener);
		fullPlayerNext.setOnClickListener(mClickListener);
		playerCollection.setOnClickListener(mClickListener);
		playerShare.setOnClickListener(mClickListener);
		playerCache.setOnClickListener(mClickListener);
		videoSeriesCacheCancel.setOnClickListener(mClickListener);
		videoSeriesCacheOk.setOnClickListener(mClickListener);
		fromLayout.setOnClickListener(mClickListener);
		mFullDefinition.setOnClickListener(mClickListener);
		for (TextView v : moreMenuItems) {
			v.setOnClickListener(mMenuListener);
		}
	}

	private long lastClickPlayBtTime = 0;

	/**
	 * 初始化OnClickListener
	 * 
	 * @return void
	 * @throws
	 */
	private void initClickListener() {
		mClickListener = new View.OnClickListener() {

			private long lastCacheButtonClickTime = 0;

			@Override
			public void onClick(View v) {
				if (playerAdapter != null && !playerAdapter.isOpenSuccess()) {
					return;
				}

				if (isAddingCache) {
					return;
				}

				switch (v.getId()) {
				case R.id.videoSV:// 显示小屏控制view
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						return;
					}
					sendHidePlayerControlLayoutHander();
					if (btPlay.getVisibility() == View.VISIBLE) {
						showOrHideSmallControlView(false);
						mHandler.removeCallbacks(hideSmallControlViewRun);
					} else {
						showOrHideSmallControlView(true);
						mHandler.postDelayed(hideSmallControlViewRun,
								controlAutoHideTime);
					}
					break;
				case R.id.full_player_recommend:// 全屏推荐
					sendHidePlayerControlLayoutHander();
					showOrHideSeriesAndRecommendLayout(v.getId());
					break;
				case R.id.full_player_select_series:// 全屏剧集
					sendHidePlayerControlLayoutHander();
					showOrHideSeriesAndRecommendLayout(v.getId());
					break;
				case R.id.player_full_airone:// 投放按钮
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						return;
					}
					if (playerAdapter != null
							&& playerAdapter.getVideoMode() != VideoMode.LOCAL) {
						if (isVideoOutLineWithToast()) {
							break;
						}
					}
					changeOrientation(true, false);
					sendHidePlayerControlLayoutHander();
					showAironeDevicesWindow();
					break;
				case R.id.full_player_menu:// 更多按钮
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						return;
					}
					sendHidePlayerControlLayoutHander();
					if (playerAdapter != null && playerAdapter.isAirOneMode()) {
						return;
					}
					if (moreMenuLayout.getVisibility() == View.VISIBLE) {
						hideMoreMenu();
					} else {
						showMoreMenu();
					}
					break;
				case R.id.play_small:
				case R.id.full_player_play_pause:// 播放/暂停
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						return;
					}
					if (System.currentTimeMillis() - lastClickPlayBtTime < 1000) {
						// 1000毫秒内多次点击播放暂停无效
						return;
					}
					lastClickPlayBtTime = System.currentTimeMillis();
					sendHidePlayerControlLayoutHander();
					play();
					break;
				case R.id.player_back_full:// 返回
				case R.id.player_back:
					sendHidePlayerControlLayoutHander();
					onBackPressed();
					break;
				case R.id.player_full_lock:// 锁定
					sendHidePlayerControlLayoutHander();
					lock = !lock;
					btLock.setBackgroundResource(lock ? R.drawable.video_fullscreen_lock_selector
							: R.drawable.video_fullscreen_unlock_selector);
					if (lock) {
						mFullTitleBar.setVisibility(View.INVISIBLE);
						mFullContorlBar.setVisibility(View.INVISIBLE);
						mFullRight.setVisibility(View.INVISIBLE);
						sendHidePlayerControlLayoutHander();
						hideMoreMenu();
						changeOrientation(true, false);
					} else {
						showFullScreenLayout();
						if (mReverse) {
							changeOrientation(false, true);
						}
					}
					break;
				case R.id.full_player_next:// 下一部
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						return;
					}
					next();
					break;
				case R.id.player_collection:// 收藏
					if (!isVideoOutLine()) {
						Reporter.logEvent(Reporter.EventId.CLICK_VIDEO_DETAIL_COLLECT_BTN);
						String furl = playerAdapter.getVideoDetail().furl.url;
						doCollection(furl, true);
					}
					break;
				case R.id.player_cache:// 显示缓存layout
					if (System.currentTimeMillis() - lastCacheButtonClickTime < 1000) {
						break;
					}
					lastCacheButtonClickTime = System.currentTimeMillis();
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						break;
					}
					// 是否已经下线
					From cacheFrom = playerAdapter.getCacheFrom();
					if (cacheFrom == null) {
						break;
					}
					if (playerAdapter.getVideoMode() != VideoMode.LIVE
							&& !isVideoOutLineWithToast()
							&& cacheFrom != null
							&& cacheFrom.btndown == 1
							&& FoneUtil
									.isNetOkWithToast(FonePlayerActivity.this)) {
						if (playerAdapter.getVideoMode() == VideoMode.SERIES) {
							videoSeriesCacheLayout.setVisibility(View.VISIBLE);
							showCacheLayout();
						} else {// 单片缓存
							// 判断是否已经缓存
							if (StorageModule
									.getInstance()
									.getOfflineCacheFileByCID(
											Long.parseLong(FoneUtil.getCIdByUrl(playerAdapter
													.getCacheFrom().defaulturl))) != null) {
								// 已经加入缓存了
								Toast.makeText(FonePlayerActivity.this,
										R.string.video_already_cached,
										Toast.LENGTH_SHORT).show();
							} else {
								startVideoCache();
							}
						}
					}
					break;
				case R.id.player_share:// 分享
					Reporter.logEvent(Reporter.EventId.CLICK_DETAIL_SHARE_BTN);
					// 是否已经下线
					if (!isVideoOutLine()) {
						showSharePopwindow();
					}
					break;
				case R.id.video_series_cache_button_cancel:// 取消缓存
					videoSeriesCacheLayout.setVisibility(View.GONE);
					break;
				case R.id.video_series_cache_button_ok:// 开始缓存
					startVideoCache();
					break;
				case R.id.player_form_layout:// 来源被点击了
					if (playerAdapter.getVideoDetail() != null
							&& playerAdapter.getVideoDetail().froms != null
							&& playerAdapter.getVideoDetail().froms.fromList != null
							&& playerAdapter.getVideoDetail().froms.fromList
									.size() > 0) {
						showFromWindow();
					}
					break;
				case R.id.full_player_definition:// 清晰度被点击了
					if (buffering) {
						// 正在缓冲中直接返回不进行处理
						return;
					}
					showDefinitionWindow(v);
					break;
				case R.id.h5_bg:// 去h5页面播放
					go3rdPlayer();
					break;
				case R.id.declaration_sure:// 已阅读法律声明，加入到缓存列表
					addCache();
					break;
				default:
					break;
				}
			}

		};
		mMenuListener = new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				sendHidePlayerControlLayoutHander();
				for (TextView v2 : moreMenuItems) {
					if (v.getId() == v2.getId()) {
						v2.setTextColor(getResources().getColor(
								R.color.video_info_tab_line));
					} else {
						v2.setTextColor(Color.WHITE);
					}
				}
				showSecondMenu(v);
			}
		};
	}

	/**
	 * 确定开始缓存
	 * 
	 * @return void
	 * @throws
	 */
	protected void startVideoCache() {
		if (!FoneUtil.isNetOkWithToast(FonePlayerActivity.this)) {
			return;
		}
		if (playerAdapter.isVip() && !UserInfoManager.isVip()) {
			// 弹出计费提示
			mHandler.sendEmptyMessage(IPlayerAdapter.FONE_PLAYER_MSG_SHOW_VIP_PAGE);
			return;
		}
		if (SystemUtil.getInstance().isUpperLimitSpace()) {
			// 判断是否到达可使用容量下线
			FoneUtil.showToast(mContext, "存储空间不足，请进行清理");
			return;
		}
		if (playerAdapter.getVideoMode() == VideoMode.SERIES) {
			if (cacheSelectedNumber > 0) {
				LegalNoticeDialog dialog = new LegalNoticeDialog(
						FonePlayerActivity.this, FoneUtil.getDeclaration(
								FonePlayerActivity.this,
								FoneConstant.CACHE_LEGAL_NOTICE));
				dialog.setListener(mClickListener);
			} else {
				// 提示：没有选择内容
				Toast.makeText(FonePlayerActivity.this,
						R.string.no_select_content, Toast.LENGTH_SHORT).show();
			}
		} else {
			LegalNoticeDialog dialog = new LegalNoticeDialog(
					FonePlayerActivity.this, FoneUtil.getDeclaration(
							FonePlayerActivity.this,
							FoneConstant.CACHE_LEGAL_NOTICE));
			dialog.setListener(mClickListener);
		}
	}

	/**
	 * 下一部
	 * 
	 * @return void
	 * @throws
	 */
	private void next() {
		sendHidePlayerControlLayoutHander();
		if (playerAdapter != null) {
			boolean hasNext = playerAdapter.hasNext();
			if (!hasNext) {
				Toast.makeText(FonePlayerActivity.this,
						R.string.player_no_next, Toast.LENGTH_SHORT).show();
			} else {
				if (!playerAdapter.isAirOneMode()) {
					playerAdapter.stop();
					playerAdapter.release();
					videoSurface.setVisibility(View.INVISIBLE);
				}
				hideMoreMenu();
				playerAdapter.next();
				resetProgressView();
				if (mFullRightSeriesRecommend.getVisibility() == View.VISIBLE) {
					mFullRightSeriesRecommend.setVisibility(View.GONE);
					mFullRightLayout.startAnimation(mRightOutAnim);
				}
			}
		}
	}

	/**
	 * 显示清晰度选择框
	 * 
	 * @param v
	 * @return void
	 * @throws
	 */
	private void showDefinitionWindow(View v) {
		sendHidePlayerControlLayoutHander();
		if (playerAdapter == null || playerAdapter.isAirOneMode()
				|| playerAdapter.getPlaRst() == null
				|| playerAdapter.getPlaRst().cnt.dfnts.dfntList.size() <= 1) {
			return;
		}
		if (definitionPopupWindow == null) {
			XyzplaRst plRst = playerAdapter.getPlaRst();
			definitionPopupWindow = new VideoDefinitionPopupWindow(mContext,
					plRst.cnt.dfnts.dfntList,
					new VideoDefinitionPopupWindow.ItemClickCallBack() {
						@Override
						public void onItemclick(Dfnt dfnt) {
							// 切换清晰度
							if (playerAdapter != null) {
								if (playerAdapter.isPlaying()) {
									if (dfnt.cur == 0) {
										playerAdapter.savePlayRecord();
										playerAdapter.stop();
										playerAdapter.release();
										videoSurface
												.setVisibility(View.INVISIBLE);
										requestVideoPlayUrl(dfnt.url, "1",
												false);
										// 保存当前清晰度
										SharedPreferenceModule.getInstance()
												.setString(DEFINITION_KEY,
														dfnt.t + "");
										// 更新清晰度背景
										updateDefinition(dfnt.t);
										if (definitionPopupWindow != null) {
											definitionPopupWindow.dismiss();
										}
									}
								}
							}

						}
					});
		} else {
			definitionPopupWindow
					.setDfntList(playerAdapter.getPlaRst().cnt.dfnts.dfntList);
		}
		if (definitionPopupWindow.isShowing()) {
			definitionPopupWindow.dismiss();
		} else {
			definitionPopupWindow.show(v);
		}
	}

	/**
	 * 是否在切换来源，解决切换来源后未继续上次的时间播放
	 */
	private boolean isChangeFrom;

	/**
	 * 显示来源选择框
	 * 
	 * @return void
	 * @throws
	 */
	private void showFromWindow() {
		if (fromWindow == null) {
			fromWindow = new VideoFromPopupWindow(
					ApplicationManage.getAplicationManageInstance(),
					playerAdapter.getCurrentFrom(),
					playerAdapter.getVideoDetail().froms.fromList,
					new VideoFromPopupWindow.ItemClickCallBack() {
						@Override
						public void onItemclick(From from, int position) {
							fromWindow.dismiss();
							if (!FoneUtil
									.isNetOkWithToast(FonePlayerActivity.this)) {
								return;
							}
							if (currentFromIndex == position) {
								return;
							}
							currentFromIndex = position;
							if (playerAdapter != null) {
								playerAdapter.stop();
								playerAdapter.release();
							}
							isChangeFrom = true;
							videoSurface.setVisibility(View.INVISIBLE);
							playerAdapter.setCurrentFrom(from);
							fromWindow.setCurrentFrom(from);
							L.v(TAG, "from = " + from.from);
						}
					});
			fromWindow.show(mTitlebarSmall);
		} else {
			if (fromWindow.isShowing()) {
				fromWindow.dismiss();
			} else {
				fromWindow.show(mTitlebarSmall);
			}
		}
	}

	/**
	 * 添加缓存
	 * 
	 * @return void
	 * @throws
	 */
	private void addCache() {
		L.v(TAG, "start add cache --- " + System.currentTimeMillis());
		final From cacheFrom = playerAdapter.getCacheFrom();
		if (cacheFrom == null) {
			return;
		}
		if (playerAdapter.getVideoMode() == VideoMode.SERIES) {
			cacheProgress.setVisibility(View.VISIBLE);
			videoSeriesCacheRuleLayout.setVisibility(View.GONE);
			videoSeriesCacheUnRuleLayout.setVisibility(View.GONE);
			isAddingCache = true;
			new Thread(new Runnable() {

				@Override
				public void run() {
					// 开始缓存
					if (cacheRst != null && cacheRst.cntsList != null
							&& cacheRst.cntsList.size() > 0) {
						List<OfflineCache> dramaTmpData = new ArrayList<OfflineCache>();
						for (DramaRst.Cnts cnts : cacheRst.cntsList) {
							if (cnts.cntList != null && cnts.cntList.size() > 0) {
								for (DramaRst.Cnt cnt : cnts.cntList) {

									if (cnt.isChecked) {
										OfflineCache itemBean = new OfflineCache();
										// 保证数据库中数据一致 添加第xxx集 使用的时候如果不需要 则截取
										itemBean.setCacheContentType(cacheRst.favtyp);
										itemBean.setCacheStoragePath(SystemUtil
												.getInstance()
												.getOfflineCachePath());
										itemBean.setCacheName(cacheRst.name);
										itemBean.setSortIndex(cnt.idx);
										if (openFrom == 42) {
											// vip
											itemBean.setCacheReportPage(42);
										} else {
											itemBean.setCacheReportPage(50);
										}

										itemBean.setCacheFromPage(OfflineCache.CACHE_FROM_PAGE_DETAIL);
										if (FoneUtil
												.getCIdByUrl(cnt.url)
												.equals(FoneUtil
														.getCIdByUrl(playerAdapter
																.getXyzPlayUrl()))) {
											itemBean.setCacheIsDetailPlay(true);
										}
										if (cacheRst.favtyp == OfflineCache.CACHE_CONTENT_TYPE_ANIMATION
												|| cacheRst.favtyp == OfflineCache.CACHE_CONTENT_TYPE_TV) {
											itemBean.setCacheEpisodeNum("第"
													+ cnt.name + "集");
										} else if (cacheRst.favtyp == OfflineCache.CACHE_CONTENT_TYPE_VARIETY) {
											itemBean.setCacheEpisodeNum(cnt.name);
										}
										itemBean.setCacheXYZPlayUrl(cnt.url);
										if (!TextUtils.isEmpty(cnt.pic)) {
											itemBean.setCacheImageUrl(cacheRst.shost
													+ FoneUtil
															.formatUrl(cnt.pic));
										}
										String dramaUrl = cacheFrom.dramaurl;
										String url = "";
										if (dramaUrl
												.startsWith("[host]/player")) {
											url = dramaUrl.substring(dramaUrl
													.indexOf("]/player") + 8);
											itemBean.setCacheDramaUrl(url);
										}
										NetCollectionActivity.formatIDS(
												itemBean, cnt.url);
										itemBean.setCacheSourceName(playerAdapter
												.getCacheFrom().from);
										itemBean.setCacheFromPage(OfflineCache.CACHE_FROM_PAGE_DETAIL);
										dramaTmpData.add(itemBean);
										cnt.isChecked = false;
									}
								}
							}
						}
						if (dramaTmpData.size() > 0) {
							cacheProgress.setVisibility(View.VISIBLE);
							L.v(TAG,
									"addCacheList time = "
											+ System.currentTimeMillis());

							StorageModule.getInstance().addCacheList(
									dramaTmpData);
							// 超时5秒钟
							mHandler.postDelayed(new Runnable() {
								@Override
								public void run() {
									if (isAddingCache) {
										isAddingCache = false;
										addCacheSuccess();
									}
								}
							}, 5000);
							mHandler.post(new Runnable() {
								@Override
								public void run() {
									// 添加缓存的同时添加到收藏
									try {
										int videoId = Integer.valueOf(FoneUtil.getVideoIdByUrl(playerAdapter
												.getVideoDetail().furl.url));
										if (!StorageModule.getInstance()
												.isFavourite(videoId)) {
											doCollection(playerAdapter
													.getVideoDetail().furl.url,
													false);
										}
									} catch (NumberFormatException e) {
										e.printStackTrace();
									}
								}
							});
						}
					}
				}
			}).start();
		} else {// 非剧集缓存
			OfflineCache itemBean = new OfflineCache();
			// 保证数据库中数据一致 添加第xxx集 使用的时候如果不需要 则截取
			itemBean.setCacheContentType(cacheFrom.favtyp);
			itemBean.setCacheName(playerAdapter.getVideoDetail().name);
			itemBean.setSortIndex(Integer.valueOf(FoneUtil
					.getVideoIdByUrl(cacheFrom.defaulturl)));
			itemBean.setCacheXYZPlayUrl(cacheFrom.defaulturl);

			if (openFrom == 42) {
				// vip
				itemBean.setCacheReportPage(42);
			} else {
				itemBean.setCacheReportPage(50);
			}

			itemBean.setCacheIsDetailPlay(true);
			itemBean.setCacheStoragePath(SystemUtil.getInstance()
					.getOfflineCachePath());
			itemBean.setCacheSourceName(playerAdapter.getCacheFrom().from);
			itemBean.setCacheFromPage(OfflineCache.CACHE_FROM_PAGE_DETAIL);
			if (!TextUtils.isEmpty(playerAdapter.getVideoDetail().pic)) {
				itemBean.setCacheImageUrl(playerAdapter.getVideoDetail().shost
						+ FoneUtil.formatUrl(playerAdapter.getVideoDetail().pic));
			}
			NetCollectionActivity.formatIDS(itemBean, cacheFrom.defaulturl);

			StorageModule.getInstance().addCache(itemBean);
			// 缓存成功
			Toast.makeText(FonePlayerActivity.this,
					R.string.add_offline_cache_success, Toast.LENGTH_SHORT)
					.show();
			// 添加缓存的同时添加到收藏
			int videoId;
			try {
				videoId = Integer
						.valueOf(FoneUtil.getVideoIdByUrl(playerAdapter
								.getVideoDetail().furl.url));
				if (!StorageModule.getInstance().isFavourite(videoId)) {
					doCollection(playerAdapter.getVideoDetail().furl.url, false);
				}
			} catch (NumberFormatException e) {
				e.printStackTrace();
			}
		}
	}

	private void addCacheSuccess() {
		cacheProgress.setVisibility(View.GONE);
		cacheSelectedNumber = 0;
		updateStartCacheButton();
		Toast.makeText(FonePlayerActivity.this,
				R.string.add_offline_cache_success, Toast.LENGTH_SHORT).show();
		videoSeriesCacheLayout.setVisibility(View.GONE);
		if (cacheRst.cntsList.get(0).showtyp == 0) {
			// 规则剧集
			ruleGridSeriesCacheItemAdapter.notifyDataSetChanged();
		} else {
			// 不规则剧集
			unRuleSeriesCacheItemAdapter.notifyDataSetChanged();
		}
	}

	private SelectSharePopwindow sharePopwindow;

	/**
	 * 显示分享popwindow
	 * 
	 * @return void
	 * @throws
	 */
	private void showSharePopwindow() {
		sharePopwindow = new SelectSharePopwindow(FonePlayerActivity.this,
				infoLayout.getHeight(), infoLayout.getWidth(),
				new ISNSShareManager.ShareStateListener() {

					@Override
					public void shareAction(int action, String info) {

					}

					@Override
					public void onUserInfoComplete(SNSUserInfo user) {

					}
				});
		ShareInfo info = new ShareInfo(
				SNSShareManager.TENCENT_WEIXIN_FRIEND_TYPE);
		String share_word_prefix = getResources().getString(
				R.string.select_share_word_prefix);
		String share_link_address = getResources().getString(
				R.string.select_share_link_address);
		info.title = playerAdapter.getVideoName();
		info.titleUrl = share_link_address;
		info.countID = FoneUtil.String2Integer(FoneUtil
				.getCIdByUrl(playerAdapter.getCurrentFrom().defaulturl));
		info.comeFrom = 2;
		info.text = share_word_prefix + playerAdapter.getVideoName();
		info.videoUrl = playerAdapter.getCurrentFrom().weibourl.replace(
				"[host]", playerAdapter.getVideoDetail().host);
		L.v("info.videoUrl", info.videoUrl);
		if (!TextUtils.isEmpty(playerAdapter.getVideoDetail().pic)) {
			info.imageUrl = playerAdapter.getVideoDetail().pic.replace(
					"[shost]", playerAdapter.getVideoDetail().shost);
		}
		info.site = "100tv";
		info.siteUrl = share_link_address;
		sharePopwindow.show(infoLayout, info);
	}

	/**
	 * 隐藏分享菜单
	 */
	private void hideSharePopWindow() {
		if (sharePopwindow != null) {
			sharePopwindow.dismiss();
		}
	}

	/**
	 * 显示缓存layout
	 * 
	 * @return void
	 * @throws
	 */
	protected void showCacheLayout() {
		if (cacheRst == null) {
			String cacheUrl = playerAdapter.getCacheFrom().dramaurl;
			if (!TextUtils.isEmpty(cacheUrl)) {
				requestCacheRst(cacheUrl);
			}
			L.v("测试",
					"详情页请求的剧集接口------------------>"
							+ playerAdapter.getCurrentFrom().dramaurl);
		} else {
			cacheProgress.setVisibility(View.GONE);
			if (cacheRst.cntsList.get(0).showtyp == 0) {
				// 规则显示
				videoSeriesCacheRuleLayout.setVisibility(View.VISIBLE);
				videoSeriesCacheUnRuleLayout.setVisibility(View.GONE);
				if (videoSeriesCachePagerAdapter == null) {
					for (DramaRst.Cnts cnts : cacheRst.cntsList) {
						cnts.isChecked = false;
					}
					cacheRst.cntsList.get(0).isChecked = true;
					videoSeriesCachePagerAdapter = new GridSeriesTabItemAdapter(
							cacheRst.cntsList, true);
					videoSeriesCachePager
							.setAdapter(videoSeriesCachePagerAdapter);
				} else {
					for (DramaRst.Cnts cnts : cacheRst.cntsList) {
						cnts.isChecked = false;
					}
					cacheRst.cntsList.get(0).isChecked = true;
					videoSeriesCachePagerAdapter.setData(cacheRst.cntsList);
				}
				if (ruleGridSeriesCacheItemAdapter != null) {
					ruleGridSeriesCacheItemAdapter.setData(cacheRst.cntsList
							.get(0).cntList);
				} else {
					ruleGridSeriesCacheItemAdapter = new RuleGridCacheItemAdapter(
							cacheRst.cntsList.get(0).cntList);
					ruleVideoSeriesCacheGridView
							.setAdapter(ruleGridSeriesCacheItemAdapter);
				}
			} else {
				// 不规则显示
				videoSeriesCacheRuleLayout.setVisibility(View.GONE);
				videoSeriesCacheUnRuleLayout.setVisibility(View.VISIBLE);
				if (unRuleSeriesCacheItemAdapter == null) {
					unRuleSeriesCacheItemAdapter = new UnRuleListCacheItemAdapter(
							cacheRst.cntsList.get(0).cntList);
					unRuleVideoSeriesCacheList
							.setAdapter(unRuleSeriesCacheItemAdapter);
				} else {
					unRuleSeriesCacheItemAdapter.setData(cacheRst.cntsList
							.get(0).cntList);
				}
			}
		}
	}

	/**
	 * 请求缓存bean
	 * 
	 * @param url
	 * @return void
	 * @throws
	 */
	private void requestCacheRst(String url) {
		cacheProgress.setVisibility(View.VISIBLE);
		Request.getInstance().drama(FoneUtil.handleUrl(url),
				new com.fone.player.client.Callback<DramaRst>() {

					@Override
					public void onSuccess(DramaRst t) {
						cacheProgress.setVisibility(View.GONE);
						if (t.result == 0) {
							// 请求成功
							if (cacheRst == null) {// 第一次请求
								cacheRst = t;
								if (cacheRst.cntsList.get(0).showtyp == 0) {// 规则显示
									cacheRst.cntsList.get(0).isChecked = true;
									ruleGridSeriesCacheItemAdapter = new RuleGridCacheItemAdapter(
											cacheRst.cntsList.get(0).cntList);
									ruleVideoSeriesCacheGridView
											.setAdapter(ruleGridSeriesCacheItemAdapter);
									videoSeriesCachePagerAdapter = new GridSeriesTabItemAdapter(
											cacheRst.cntsList, false);
									videoSeriesCachePager
											.setAdapter(videoSeriesCachePagerAdapter);
									refreshCacheTabView();
									videoSeriesCacheRuleLayout
											.setVisibility(View.VISIBLE);
									videoSeriesCacheUnRuleLayout
											.setVisibility(View.GONE);
									videoSeriesCachePager
											.setOnItemClickListener(new AdapterView.OnItemClickListener() {
												@Override
												public void onItemClick(
														AdapterView<?> arg0,
														View arg1, int arg2,
														long arg3) {
													DramaRst.Cnts cnts = cacheRst.cntsList
															.get(arg2);
													if (!cnts.isChecked) {
														for (DramaRst.Cnts cs : cacheRst.cntsList) {
															cs.isChecked = false;
														}
														cnts.isChecked = true;
														videoSeriesCachePagerAdapter
																.notifyDataSetChanged();
														if (cnts.cntList == null
																|| cnts.cntList
																		.size() == 0) {
															videoSeriesCacheRuleLayout
																	.setVisibility(View.GONE);
															cacheProgress
																	.setVisibility(View.VISIBLE);
															requestCacheRst(cnts.url);
														} else {
															ruleGridSeriesCacheItemAdapter
																	.setData(cnts.cntList);
														}
													}
												}
											});
									ruleVideoSeriesCacheGridView
											.setOnItemClickListener(new AdapterView.OnItemClickListener() {
												@Override
												public void onItemClick(
														AdapterView<?> arg0,
														View arg1, int arg2,
														long arg3) {
													DramaRst.Cnt cnt = (Cnt) ruleGridSeriesCacheItemAdapter
															.getItem(arg2);
													// 当前是否选中
													if (cnt.isChecked == true) {// 已经选中
														cnt.isChecked = false;
														cacheSelectedNumber--;
														if (cacheSelectedNumber < 0) {
															cacheSelectedNumber = 0;
														}
														updateStartCacheButton();
													} else {// 未选中
															// 是否在缓存列表里了
														if (cnt.cacheState != -1) {// 在缓存列表里
															return;
														} else {
															cnt.isChecked = true;
															cacheSelectedNumber++;
															updateStartCacheButton();
														}
													}

													ruleGridSeriesCacheItemAdapter
															.notifyDataSetChanged();
												}
											});
								} else {
									unRuleSeriesCacheItemAdapter = new UnRuleListCacheItemAdapter(
											cacheRst.cntsList.get(0).cntList);
									unRuleVideoSeriesCacheList
											.setAdapter(unRuleSeriesCacheItemAdapter);
									unRuleVideoSeriesCacheList
											.setOnItemClickListener(new AdapterView.OnItemClickListener() {

												@Override
												public void onItemClick(
														AdapterView<?> arg0,
														View arg1, int arg2,
														long arg3) {
													DramaRst.Cnt cnt = (Cnt) unRuleSeriesCacheItemAdapter
															.getItem(arg2);
													// 当前是否选中
													if (cnt.isChecked == true) {// 已经选中
														cnt.isChecked = false;
														cacheSelectedNumber--;
														if (cacheSelectedNumber < 0) {
															cacheSelectedNumber = 0;
														}
														updateStartCacheButton();
													} else {// 未选中
															// 是否在缓存列表里了
														if (cnt.cacheState != -1) {// 在缓存队列里
															return;
														} else {
															cnt.isChecked = true;
															cacheSelectedNumber++;
															updateStartCacheButton();
														}
													}
													unRuleSeriesCacheItemAdapter
															.notifyDataSetChanged();
												}

											});
									videoSeriesCacheRuleLayout
											.setVisibility(View.GONE);
									videoSeriesCacheUnRuleLayout
											.setVisibility(View.VISIBLE);
								}
							} else {
								for (int i = 0; i < cacheRst.cntsList.size(); i++) {
									DramaRst.Cnts cnts = cacheRst.cntsList
											.get(i);
									if (t != null
											&& t.cntsList != null
											&& t.cntsList.get(i).cntList != null
											&& t.cntsList.get(i).cntList.size() != 0) {
										cnts.cntList = t.cntsList.get(i).cntList;
										if (cnts.showtyp == 0) {
											videoSeriesCacheRuleLayout
													.setVisibility(View.VISIBLE);
											videoSeriesCacheUnRuleLayout
													.setVisibility(View.GONE);
											ruleGridSeriesCacheItemAdapter
													.setData(cnts.cntList);
										} else {
											videoSeriesCacheRuleLayout
													.setVisibility(View.GONE);
											videoSeriesCacheUnRuleLayout
													.setVisibility(View.VISIBLE);
											unRuleSeriesCacheItemAdapter
													.setData(cnts.cntList);
										}
										break;
									}
								}
							}
						} else {
							if (t != null) {
								L.v(TAG, "request cache series : "
										+ t.error.errormsg);
							}
							Toast.makeText(FonePlayerActivity.this,
									R.string.video_cannot_cache,
									Toast.LENGTH_SHORT).show();
						}
					}

					@Override
					public void onFailure(Error error) {
						cacheProgress.setVisibility(View.GONE);
						if (!error.isNetworkError()) {
							if (error.getStatus() == 404) {
								// 未找到
								Toast.makeText(mContext,
										R.string.video_outline_text,
										Toast.LENGTH_SHORT).show();
							} else {
								L.v(TAG, "请求缓存剧集error" + error.getReason());
								// Toast.makeText(mContext, error.getReason(),
								// Toast.LENGTH_SHORT).show();
							}
						}
					}
				});
	}

	/**
	 * 更新开始缓存按钮上的数字
	 * 
	 * @return void
	 * @throws
	 */
	private void updateStartCacheButton() {
		if (cacheSelectedNumber == 0) {
			videoSeriesCacheOk.setText(R.string.player_video_series_cache_ok);
			videoSeriesCacheOk.setTextColor(getResources().getColor(
					R.color.tv_normal));
		} else {
			videoSeriesCacheOk
					.setText(getString(R.string.player_video_series_cache_ok)
							+ "(" + cacheSelectedNumber + ")");
			videoSeriesCacheOk.setTextColor(getResources().getColor(
					R.color.video_info_tab_line));
		}
	}

	/**
	 * 显示更多菜单
	 * 
	 * @return void
	 * @throws
	 */
	protected void showMoreMenu() {
		if (moreMenuLayout.getVisibility() != View.VISIBLE) {
			moreMenuLayout.setVisibility(View.VISIBLE);
			fullMore.setBackgroundResource(R.drawable.detail_icon_play_more_click);
			for (TextView tv : moreMenuItems) {
				tv.setTextColor(Color.WHITE);
			}
		}
	}

	/**
	 * 隐藏更多菜单
	 * 
	 * @return void
	 * @throws
	 */
	private void hideMoreMenu() {
		if (moreMenuLayout.getVisibility() == View.VISIBLE) {
			hideSecondMenu();
			moreMenuLayout.setVisibility(View.INVISIBLE);
			fullMore.setBackgroundResource(R.drawable.detail_icon_play_more);
		}
	}

	/**
	 * 显示二级菜单:3D 倍速 字幕
	 * 
	 * @param v
	 * @return void
	 * @throws
	 */
	private void showSecondMenu(View v) {
		hideSecondMenu();
		LayoutInflater inflater = LayoutInflater.from(FonePlayerActivity.this);
		View popContent = null;
		ListView mlist = null;
		switch (v.getId()) {
		case R.id.video_full_3d:
			// 检查是否是软解
			if (playerAdapter.getPlayerDecoderRole() != 2) {
				hideMoreMenu();
				showChangeSwDecoderDialog(getString(R.string.video_fullscreen_3d)
						+ getString(R.string.dialog_switch_swdecoder_messgae));
				return;
			}
			popContent = inflater.inflate(R.layout.second_menu_popwindow, null);
			mlist = (ListView) popContent
					.findViewById(R.id.video_second_menu_list);
			mlist.setAdapter(new MenuSwithAdapter(current3D));
			mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int pos, long id) {
					hideMoreMenu();
					if (pos == 0) {
						if (playerAdapter != null) {
							boolean res = playerAdapter.set3DState(1);
							if (res) {
								current3D = 1;
							}
						}
					} else {
						if (playerAdapter != null) {
							boolean res = playerAdapter.set3DState(0);
							if (res) {
								current3D = 0;
							}
						}
					}
				}
			});
			break;
		case R.id.video_full_speed:// 倍速
			// 直播模式不支持倍速
			if (playerAdapter.isLiveVideo()) {
				hideMoreMenu();
				return;
			}
			// 检查是否是软解
			if (playerAdapter.getPlayerDecoderRole() != 2) {
				hideMoreMenu();
				showChangeSwDecoderDialog(getString(R.string.video_fullscreen_speed)
						+ getString(R.string.dialog_switch_swdecoder_messgae));
				return;
			}
			popContent = inflater.inflate(R.layout.second_menu_popwindow, null);
			mlist = (ListView) popContent
					.findViewById(R.id.video_second_menu_list);
			mlist.setAdapter(new MenuRateAdapter(playerAdapter.getCurrentRate()));
			mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int pos, long id) {
					hideMoreMenu();
					if (pos != playerAdapter.getCurrentRate()) {
						playerAdapter.setPlayRate(pos);
					}
				}
			});
			break;
		case R.id.video_full_subtitle:// 字幕
			if (playerAdapter != null) {
				if (playerAdapter.getPlayerDecoderRole() == 1) {// 硬解码不支持字幕
					L.v(TAG, "硬解码不支持字幕！");
					hideMoreMenu();
					showChangeSwDecoderDialog(getString(R.string.video_fullscreen_subtitle)
							+ getString(R.string.dialog_switch_swdecoder_messgae));
					return;
				}
				List<String> subChannels = new ArrayList<String>();
				int subCount = playerAdapter.getSubCount();
				if (playerAdapter.getVideoMode() != VideoMode.LOCAL) {
					subChannels.add(getString(R.string.nothing));
				} else if (subCount <= 0) {
					subCount = 1;
					subChannels.add(getString(R.string.nothing));
				} else {
					subChannels = playerAdapter.getSubChannels();
				}
				popContent = inflater.inflate(R.layout.second_menu_popwindow,
						null);
				mlist = (ListView) popContent
						.findViewById(R.id.video_second_menu_list);
				mlist.setAdapter(new MenuSubAdapter(subChannels, currentSub));
				mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int pos, long id) {
						hideMoreMenu();
						if (playerAdapter.getSubCount() <= 0) {
							return;
						}
						if (pos != currentSub) {
							if (playerAdapter.setCurrentSubChannel(pos)) {
								currentSub = pos;
								Toast.makeText(FonePlayerActivity.this,
										R.string.switch_audio_channel,
										Toast.LENGTH_LONG).show();
							}
						}
					}
				});

			}

			break;
		case R.id.video_full_track:// 音轨
			if (playerAdapter != null) {

				if (playerAdapter.getPlayerDecoderRole() == 1) {// 硬解码不支持字幕
					L.v(TAG, "硬解码不支持音轨！");
					hideMoreMenu();
					showChangeSwDecoderDialog(getString(R.string.video_fullscreen_track)
							+ getString(R.string.dialog_switch_swdecoder_messgae));
					return;
				}

				int audioCount = playerAdapter.getAudioChannelCount();
				List<String> audioChannels = new ArrayList<String>();
				if (playerAdapter.getVideoMode() != VideoMode.LOCAL) {
					audioCount = 1;
					audioChannels.add(getString(R.string.nothing));
					currentAudioChannel = 0;
				} else if (audioCount <= 0) {
					audioCount = 1;
					audioChannels.add(getString(R.string.nothing));
					currentAudioChannel = 0;
				} else {
					audioChannels = playerAdapter.getAudioChannels();
					currentAudioChannel = playerAdapter
							.getCurrentAudioChannel();
				}
				popContent = inflater.inflate(R.layout.second_menu_popwindow,
						null);
				mlist = (ListView) popContent
						.findViewById(R.id.video_second_menu_list);
				mlist.setAdapter(new MenuTrackAdapter(audioChannels,
						currentAudioChannel));
				mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> parent, View view,
							int pos, long id) {
						hideMoreMenu();
						if (pos != currentAudioChannel) {
							if (playerAdapter.setCurrentAudioChannel(pos)) {
								currentAudioChannel = pos;
								Toast.makeText(FonePlayerActivity.this,
										R.string.switch_audio_channel,
										Toast.LENGTH_LONG).show();
							}
						}
					}
				});

			}
			break;

		case R.id.video_full_hwplus:// 省电加速
			popContent = inflater.inflate(R.layout.second_menu_popwindow, null);
			mlist = (ListView) popContent
					.findViewById(R.id.video_second_menu_list);
			currentDecoderMode = playerAdapter.getPlayerDecoderRole() == 0 ? 1
					: 0;
			mlist.setAdapter(new MenuSwithAdapter(currentDecoderMode));
			mlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> parent, View view,
						int pos, long id) {
					hideMoreMenu();
					int state = pos == 0 ? 1 : 0;
					if (playerAdapter != null) {
						if (currentDecoderMode == state) {
							return;
						}
						playerAdapter.stop();
						playerAdapter.release();
						playerAdapter.updatePlayRecord2MediaInfo();
						if (state == 0) {// 关闭省电加速需要隐藏videoSurface
							L.v(TAG, "hwplus decoder start close");
							videoSurface.setVisibility(View.INVISIBLE);
						} else {
							L.v(TAG, "hwplus decoder start open");
							// 打开省电加速需要进行监听时间，15秒以后还没有打开就提示打开失败
							mHandler.postDelayed(hwPlusRunable, 15000);
						}
						playerAdapter.doSwithHwPlus(state);
					}
				}
			});
			break;
		default:
			break;
		}
		secondWindow = new PopupWindow(popContent, ScreenUtil.dp2px(80),
				LayoutParams.WRAP_CONTENT);
		secondWindow.setFocusable(true);
		secondWindow.setBackgroundDrawable(new BitmapDrawable());
		secondWindow.setOutsideTouchable(true);
		secondWindow.showAsDropDown(v, -v.getWidth(), -v.getHeight());
	}

	private Runnable hwPlusRunable = new Runnable() {

		@Override
		public void run() {
			Toast.makeText(FonePlayerActivity.this,
					R.string.video_not_support_future, Toast.LENGTH_SHORT)
					.show();
			// 停止播放
			playerAdapter.stop();
			playerAdapter.release();
			videoSurface.setVisibility(View.INVISIBLE);
			playerAdapter.play();
		}
	};

	/**
	 * 显示软解转换对话框
	 * 
	 * @param message
	 *            提示内容
	 * @return void
	 * @throws
	 */
	private void showChangeSwDecoderDialog(String message) {
		CustomAlertDialog.Builder builder = new CustomAlertDialog.Builder(
				FonePlayerActivity.this, getString(R.string.dialog_title),
				message, getString(R.string.dialog_switch),
				getString(R.string.dialog_cancel),
				new CustomAlertDialog.Builder.CustomDialogOnClickListener() {
					@Override
					public void onRight() {
						// 取消
						playerDialog.dismiss();
					}

					@Override
					public void onLeft() {
						// 转换
						playerAdapter.stop();
						playerAdapter.release();
						playerAdapter.updatePlayRecord2MediaInfo();
						videoSurface.setVisibility(View.INVISIBLE);
						playerAdapter.doSwitchSwDecoder();
					}
				});
		playerDialog = builder.create();
		playerDialog.show();
	}

	private void hideSecondMenu() {
		if (secondWindow != null && secondWindow.isShowing()) {
			secondWindow.dismiss();
		}
	}

	/**
	 * 如果选集/推荐layout显示，此变量代表mFullRecommend/mFullSeries的id
	 */
	private int seriesOrRecommendId = 0;

	/**
	 * @param id
	 *            显示或者隐藏推荐选集layout
	 * 
	 * @return void
	 * @throws
	 */
	private void showOrHideSeriesAndRecommendLayout(int id) {
		if (mFullRightSeriesRecommend.getVisibility() == View.GONE) {
			mFullRightSeriesRecommend.setVisibility(View.VISIBLE);
			mFullRightLayout.startAnimation(mRightInAnim);
			switchSeriesOrRecommend(id);
		} else {
			if (id != seriesOrRecommendId) {
				// 切换
				switchSeriesOrRecommend(id);
			} else {
				// 隐藏
				hideFullRightLayout();
			}
		}
	}

	/**
	 * 隐藏全屏右侧的选集推荐layout
	 * 
	 * @return void
	 * @throws
	 */
	private void hideFullRightLayout() {
		mFullRecommend.setTextColor(getResources().getColor(
				R.color.video_full_recommend_series_textcolor));
		mFullSeries.setTextColor(getResources().getColor(
				R.color.video_full_recommend_series_textcolor));
		mFullRightLayout.startAnimation(mRightOutAnim);
		mRightOutAnim.setAnimationListener(new Animation.AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				mFullRightSeriesRecommend.setVisibility(View.GONE);
			}
		});
	}

	/**
	 * 切换选集或者推荐
	 * 
	 * @param id
	 * @return void
	 * @throws
	 */
	private void switchSeriesOrRecommend(int id) {
		if (id == R.id.full_player_recommend) {
			mFullRecommend.setTextColor(getResources().getColor(
					R.color.video_info_tab_line));
			mFullSeries.setTextColor(getResources().getColor(
					R.color.video_full_recommend_series_textcolor));
			// 显示推荐
			fullPlayerLinkList.setVisibility(View.VISIBLE);
			fullPlayerRuleSeriesLayout.setVisibility(View.GONE);
			seriesOrRecommendId = R.id.full_player_recommend;
			// 本地播放不显示推荐了
			if (flinkvideoRst != null) {
				updateFLinkVideoView();
			}
			// }
		} else {
			// 显示选集
			mFullSeries.setTextColor(getResources().getColor(
					R.color.video_info_tab_line));
			mFullRecommend.setTextColor(getResources().getColor(
					R.color.video_full_recommend_series_textcolor));
			if (seriesRst != null && seriesRst.cntsList.get(0).showtyp == 0) {// 规则显示
				fullPlayerRuleSeriesLayout.setVisibility(View.VISIBLE);
				fullPlayerLinkList.setVisibility(View.GONE);
			} else if (seriesRst != null
					&& seriesRst.cntsList.get(0).showtyp == 1) {// 不规则显示
				fullPlayerLinkList.setVisibility(View.VISIBLE);
				if (unRuleSeriesItemAdapter != null) {
					fullPlayerLinkList.setAdapter(unRuleSeriesItemAdapter);
				} else {
					unRuleSeriesItemAdapter = new UnRuleSeriesItemAdapter(
							seriesRst.cntsList.get(0).cntList,
							playerAdapter.getXyzPlayUrl());
					fullPlayerLinkList.setAdapter(unRuleSeriesItemAdapter);
				}
				fullPlayerLinkList.setOnScrollListener(fullLinkScrollListener);
				fullPlayerLinkList
						.setOnItemClickListener(fullUnRuleItemClickListener);
			}
			seriesOrRecommendId = R.id.full_player_select_series;
		}
	}

	/**
	 * 请求本地视频关联视频列表(已过时，现在本地播放不需要显示推荐视频了)
	 * 
	 * @return void
	 * @throws
	 */
	@Deprecated
	private void requestLocalLinkVideo() {

		if (playerAdapter != null) {
			Request.getInstance().rcmd(1,
					new com.fone.player.client.Callback<RcmdRst>() {

						@Override
						public void onSuccess(RcmdRst t) {
							if (playerAdapter == null) {
								return;
							}
							if (t.result == 0) {
								rcmdRst = t;
								if (lvrAdapter == null) {
									lvrAdapter = new LocalVideoRelatedAdapter(
											rcmdRst.rcmds.rcmdList,
											rcmdRst.shost);
								} else {
									lvrAdapter.setData(rcmdRst.shost,
											rcmdRst.rcmds.rcmdList);
								}
								fullPlayerLinkList.setAdapter(lvrAdapter);
								fullPlayerLinkList
										.setOnScrollListener(fullLinkScrollListener);
								fullPlayerLinkList
										.setOnItemClickListener(new AdapterView.OnItemClickListener() {
											@Override
											public void onItemClick(
													AdapterView<?> arg0,
													View arg1, int arg2,
													long arg3) {
												if (FoneUtil
														.isNetOkWithToast(FonePlayerActivity.this)) {
													RcmdRst.Rcmd rcmd = rcmdRst.rcmds.rcmdList
															.get(arg2);
													// Intent i = new Intent();
													// i.putExtra("from",
													// PlayerFrom.LINKVIDEO.name());
													// i.putExtra("action",
													// PlayerAction.FULLPLAY.name());
													// i.putExtra("xyzplay",
													// rcmd.url);
													// handNewIntent(i);
													VideoPlayerMessage msg = new VideoPlayerMessage();
													msg.what = VideoPlayerMessage.MESSGAE_OPEN_RELEATED;
													msg.obj = new LinkVideoEvent(
															rcmd.vturl,
															rcmd.url,
															LinkVideoFrom.LOCALLINK,
															rcmd.name);
													EventBus.getDefault().post(
															msg);
												}
											}
										});
							} else {
								L.v(TAG, "requestLocalLinkVideo   "
										+ t.error.errormsg);
								Toast.makeText(mContext, t.error.errormsg,
										Toast.LENGTH_SHORT).show();
							}
						}

						@Override
						public void onFailure(Error error) {
							// 提示
							if (!error.isNetworkError()) {
								L.v(TAG, "requestLocalLinkVideo  onFailure  "
										+ error.getReason());
								Toast.makeText(mContext, error.getReason(),
										Toast.LENGTH_SHORT).show();
							}
						}
					});
		}

	}

	/**
	 * 更新全屏相关视频View
	 * 
	 * @param id
	 * @return void
	 * @throws
	 */
	private void updateFLinkVideoView() {
		// 切换推荐
		if (fvrAdapter == null) {
			if (flinkvideoRst != null && flinkvideoRst.rcmds != null
					&& flinkvideoRst.rcmds.rcmdList != null) {
				fvrAdapter = new FullVideoRelatedAdapter(
						flinkvideoRst.rcmds.rcmdList, flinkvideoRst.shost);
				fullPlayerLinkList.setAdapter(fvrAdapter);
			}
		} else {
			fvrAdapter.setData(flinkvideoRst.shost,
					flinkvideoRst.rcmds.rcmdList);
		}
		fullPlayerLinkList.setAdapter(fvrAdapter);
		fullPlayerLinkList.setOnScrollListener(fullLinkScrollListener);
		fullPlayerLinkList.setOnItemClickListener(fullLinkItemClickListener);
	}

	/**
	 * 请求全屏关联视频
	 * 
	 * @return void
	 * @throws
	 */
	private void requestFullLinkVideo() {
		if (playerAdapter != null && playerAdapter.getPlaRst() != null) {
			String flinkurl = FoneUtil
					.handleUrl(playerAdapter.getPlaRst().lkurl);
			Request.getInstance().flinkvideo(flinkurl,
					new com.fone.player.client.Callback<FlinkvideoRst>() {

						@Override
						public void onSuccess(FlinkvideoRst t) {
							if (playerAdapter == null) {
								return;
							}
							flinkvideoRst = t;
							if (t.result == 0) {
								updateFLinkVideoView();
							} else {
								L.v(TAG, "requestFullLinkVideo error "
										+ t.error.errormsg);
							}
						}

						@Override
						public void onFailure(Error error) {
							// 提示
							if (!error.isNetworkError()) {
								L.v(TAG, "requestFullLinkVideo onFailure "
										+ error.getReason());
							}
						}
					});
		}
	}

	private AdapterView.OnItemClickListener fullLinkItemClickListener = new AdapterView.OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			if (isBuffering()) {
				return;
			}
			if (FoneUtil.isNetOkWithToast(FonePlayerActivity.this)) {
				FlinkvideoRst.Rcmd rcmd = flinkvideoRst.rcmds.rcmdList
						.get(arg2);
				VideoPlayerMessage msg = new VideoPlayerMessage();
				msg.what = VideoPlayerMessage.MESSGAE_OPEN_RELEATED;
				msg.obj = new LinkVideoEvent(rcmd.vturl, rcmd.url,
						LinkVideoFrom.FULLLINK, rcmd.name);
				EventBus.getDefault().post(msg);
				hideFullRightLayout();
			}
		}
	};

	/**
	 * 更新数据
	 */
	private synchronized void updateData() {
		L.v(TAG, "updateData----");
		VideoMode mode = playerAdapter.getVideoMode();
		if (mode == null) {
			return;
		}
		int width = getResources().getDisplayMetrics().widthPixels > getResources()
				.getDisplayMetrics().heightPixels ? getResources()
				.getDisplayMetrics().heightPixels : getResources()
				.getDisplayMetrics().widthPixels;
		if (mode == VideoMode.LOCAL || mode == VideoMode.NETWORK) {
			mFullRecommend.setVisibility(View.GONE);
			mFullSeries.setVisibility(View.GONE);
			mFullDefinition.setVisibility(View.GONE);
		} else if (action != PlayerAction.FULLPLAY) {
			if (tabs != null) {
				tabs.invalidate();
			}
			switch (mode) {
			case SERIES:// 剧集
				seriesModeAdapter = new SeriesModeAdapter(
						getSupportFragmentManager(),
						playerAdapter.getCurrentFrom().dramaurl,
						playerAdapter.getXyzPlayUrl(),
						playerAdapter.getVideoDetail().addcommenturl,
						playerAdapter.getVideoDetail().commenturl,
						playerAdapter.getVideoDetail().linkurl);
				pager.removeAllViews();
				pager.setAdapter(seriesModeAdapter);
				tabs.setTabWidthPx(width / 4);
				tabs.setCurrentPostion(1);
				break;
			case LIVE:// 直播
				liveModeAdapter = new LiveModeAdapter(
						getSupportFragmentManager(),
						playerAdapter.getVideoDetail().linkurl);
				pager.removeAllViews();
				pager.setAdapter(liveModeAdapter);
				tabs.setTabWidthPx(width / 2);
				tabs.setCurrentPostion(0);
				break;
			case SINGLE:// 单片
				singleModeAdapter = new SingleModeAdapter(
						getSupportFragmentManager(),
						playerAdapter.getVideoDetail());
				pager.removeAllViews();
				pager.setAdapter(singleModeAdapter);
				tabs.setTabWidthPx(width / 3);
				tabs.setCurrentPostion(0);
				break;
			case SHORT:// 短视频
				shortModeAdapter = new ShortModeAdapter(
						getSupportFragmentManager(),
						playerAdapter.getVideoDetail());
				pager.setAdapter(shortModeAdapter);
				tabs.setTabWidthPx(width / 2);
				tabs.setCurrentPostion(0);
				break;
			default:
				break;
			}
			final int pageMargin = (int) TypedValue.applyDimension(
					TypedValue.COMPLEX_UNIT_DIP, 4, getResources()
							.getDisplayMetrics());
			pager.setPageMargin(pageMargin);
			pager.setOffscreenPageLimit(3);
			tabs.setTextSize(ScreenUtil.dp2px(15));
			tabs.setTextSelectedColor(getResources().getColor(
					R.color.video_info_tab_line));
			tabs.setOnPageChangeListener(pageChangeListener);
			tabs.setViewPager(pager);
			mFullDefinition.setVisibility(View.VISIBLE);
			mFullRecommend.setVisibility(View.VISIBLE);
		}
		if (mode != VideoMode.SERIES) {
			mFullSeries.setVisibility(View.GONE);
		} else {
			mFullSeries.setVisibility(View.VISIBLE);
		}
		if (mode == VideoMode.LIVE || playerAdapter.isLiveVideo()) {// 直播不不能缓存，不显示时间
			playerCache
					.setBackgroundResource(R.drawable.detail_icon_download_un);
			tvFullProgress.setVisibility(View.INVISIBLE);
			tvFullDuration.setVisibility(View.INVISIBLE);
			tvSmallDuration.setVisibility(View.GONE);
			tvSmallProgress.setVisibility(View.GONE);
		} else {// 非直播显示时间，缓存
			if (playerAdapter.getCacheFrom() != null
					&& playerAdapter.getCacheFrom().btndown == 1) {
				playerCache
						.setBackgroundResource(R.drawable.video_detail_cache_selector);
			} else {
				// 不能下载
				playerCache
						.setBackgroundResource(R.drawable.detail_icon_download_un);
			}
			tvFullProgress.setVisibility(View.VISIBLE);
			tvFullDuration.setVisibility(View.VISIBLE);
			tvSmallDuration.setVisibility(View.VISIBLE);
			tvSmallProgress.setVisibility(View.VISIBLE);
		}
		if (!TextUtils.isEmpty(playerAdapter.getVideoName())) {
			mTitleFull.setText(playerAdapter.getVideoName());
			mTitleSmall.setText(playerAdapter.getVideoName());
		}
		if (playerAdapter.getVideoDetail() != null) {
			updateCollectionIcon();
		}
		resetProgressView();
	}

	/**
	 * 重置播放进度view
	 * 
	 * @return void
	 * @throws
	 */
	private void resetProgressView() {
		L.v(TAG, "resetProgressView");
		tvFullProgress.setText(R.string.player_video_default_time);
		tvSmallProgress.setText(R.string.player_video_default_time);
		mSeekBar.setProgress(0);
		mSeekBar_full.setProgress(0);
		mSeekBar.setMax(0);
		mSeekBar_full.setMax(0);
	}

	private ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() {

		@Override
		public void onPageSelected(int arg0) {
			FoneUtil.hideInputMethod(FonePlayerActivity.this);
			FoneUtil.isNetOkWithToast(FonePlayerActivity.this);
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	};

	/**
	 * 显示原网页播放背景
	 */
	private void showH5background() {
		h5bg.setVisibility(View.VISIBLE);
		playSmallControlLayout.setVisibility(View.GONE);
	}

	/**
	 * 隐藏原网页播放背景
	 */
	private void hideH5background() {
		h5bg.setVisibility(View.GONE);
	}

	/**
	 * 初始化动画
	 * 
	 * @return void
	 * @throws
	 */
	private void initAnimations() {
		mRightInAnim = AnimationUtils.loadAnimation(
				ApplicationManage.getAplicationManageInstance(),
				R.anim.push_right_in);
		mRightOutAnim = AnimationUtils.loadAnimation(
				ApplicationManage.getAplicationManageInstance(),
				R.anim.push_right_out);
	}

	/**
	 * 初始化外部广播接收器
	 */
	private void initPlayerExternalEventReceiver() {
		eventReceiver = new PlayerExternalEventReceiver(this);
	}

	/**
	 * 初始化播放控制
	 */
	private void initPlayerAdapter() {
		playerAdapter = new FonePlayerAdapter(videoSurface) {
			@Override
			protected void sendMessage2UI(Message msg) {
				if (mHandler != null) {
					L.v(TAG, "receiver message what = " + msg.what);
					mHandler.sendMessage(msg);
				}
			}
		};
	}

	/**
	 * 初始化Handler
	 */
	@SuppressLint("HandlerLeak")
	private void initHandler() {
		mHandler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);

				switch (msg.what) {
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_PREPARED:// 播放器准备就绪
					mHandler.removeCallbacks(hwPlusRunable);
					if (stop) {
						playerAdapter.stop();
						break;
					}
					dismessProgressDialog();
					updateMediaDuring();
					// 启动新线程, 控制进度条
					if (mSeekBarThread != null) {
						mSeekBarThread.setStop(true);
						mSeekBarThread.interrupt();
						mSeekBarThread = null;
					}
					mSeekBarThread = new SeekBarThread();
					mSeekBarThread.setDaemon(true);
					mSeekBarThread.start();
					mSeekBar.setOnSeekBarChangeListener(new FoneOnSeekBarChangeListener()); // 监听进度条拖动事件
					mSeekBar_full
							.setOnSeekBarChangeListener(new FoneOnSeekBarChangeListener()); // 监听进度条拖动事件
					btPlay.setBackgroundResource(R.drawable.video_detail_pause_selector);
					btPlayFull
							.setBackgroundResource(R.drawable.video_fullscreen_pause_selector);
					if (getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT) {
						showOrHideSmallControlView(false);
					} else {
						sendHidePlayerControlLayoutHander();
					}
					// 取消那些网络提示
					if (mHandler
							.hasMessages(IPlayerAdapter.FONE_PLAYER_MSG_PLAY_TIMEOUT)) {
						mHandler.removeMessages(IPlayerAdapter.FONE_PLAYER_MSG_PLAY_TIMEOUT);
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_PLAYING_PAUSE:// 暂停或者播放
					updatePlayButton();
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_PREPARING:// 准备中
					showProgressDialog(
							getString(R.string.video_loading_message), false);
					tvSubtitle.setVisibility(View.GONE);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_PLAY_COMPLETION:// 播放完成
					L.v(TAG, "player play completion!");
					// 隐藏SurfaceView
					if (videoSurface.getVisibility() == View.VISIBLE) {
						videoSurface.setVisibility(View.INVISIBLE);
					}
					FonePlayerAdapter.setHwPlusSupport(0);
					// 隐藏手势框
					genstureLayout.setVisibility(View.GONE);
					if (playerAdapter == null) {
						break;
					}
					resetProgressView();
					btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
					btPlayFull
							.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
					tvSubtitle.setVisibility(View.GONE);
					if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
						mHandler.removeCallbacks(hideFullScreenLayoutRunnable);
						showFullScreenLayout();
					} else {
						mHandler.removeCallbacks(hideSmallControlViewRun);
						showOrHideSmallControlView(true);
					}
					if (openFrom == THIRDPARTY) {
						ApplicationManage.getAplicationManageInstance()
								.exitSystem();
						return;
					} else {
						if (playerAdapter.getVideoMode() != VideoMode.LOCAL) {
							if (!FoneUtil.isNetOk(FonePlayerActivity.this)) {
								return;
							}
						}
						boolean hasNext = playerAdapter.hasNext();
						L.v(TAG, "player has next == " + hasNext);
						if (!hasNext) {
							if (playerAdapter.getVideoMode() == VideoMode.LOCAL) {
								finish();
							} else if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
								unlock();
								dismessProgressDialog();
								onBackPressed();
							} else {
								dismessProgressDialog();
							}
						} else {
							hideMoreMenu();
							playerAdapter.next();
							resetProgressView();
							mFullRightSeriesRecommend.setVisibility(View.GONE);
							mFullRightLayout.startAnimation(mRightOutAnim);
						}
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_AIRONE_START:// 开始投放了
					videoSurface.setVisibility(View.INVISIBLE);
					btPlay.setBackgroundResource(R.drawable.video_detail_pause_selector);
					btPlayFull
							.setBackgroundResource(R.drawable.video_fullscreen_pause_selector);
					dismessProgressDialog();
					String deviceName = (String) msg.obj;
					Toast.makeText(
							FonePlayerActivity.this,
							String.format(
									getString(R.string.airone_open_success),
									deviceName), Toast.LENGTH_SHORT).show();
					showFullScreenLayout();
					showAirOnePlayingLayout();
					changeOrientation(true, false);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_UPDATE_UI_DATA:// 初始化数据请求完成，更新UI显示
					updateData();
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_AIRONE_STOPED:// airone停止播放
					mFullRecommend.setVisibility(View.VISIBLE);
					hideAirOnePlayingLayout();
					mListener.enable();
					if (!stop
							&& (playerAdapter.getCurrentFrom() == null || playerAdapter
									.getCurrentFrom().toply == 0)) {
						playerAdapter.updatePlayRecord2MediaInfo();
						play();
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_AIRONE_NEXT_SUCCESS:// airone下一集
					updateMediaDuring();
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_VIDEO_GET_FAILURE:// 视频获取错误
					dismessProgressDialog();
					finish();
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_VIDEO_FROM_CHANGED:// 改变了视频来源
					L.v(TAG, "FONE_PLAYER_MSG_VIDEO_FROM_CHANGED");
					if (openFrom == WEBVIEW) {
						openFrom = SPECIAL;
					}
					if (!playerAdapter.isAirOneMode()
							&& playerAdapter.isPlaying()) {
						playerAdapter.stop();
						playerAdapter.release();
					}
					if (playerAdapter.isLiveVideo()) {// 直播不不能缓存，不显示时间
						playerCache
								.setBackgroundResource(R.drawable.detail_icon_download_un);
						tvFullProgress.setVisibility(View.INVISIBLE);
						tvFullDuration.setVisibility(View.INVISIBLE);
						tvSmallProgress.setVisibility(View.GONE);
						tvSmallDuration.setVisibility(View.GONE);
					} else {// 非直播显示时间，缓存
						if (playerAdapter.getCacheFrom() != null
								&& playerAdapter.getCacheFrom().btndown == 1) {
							playerCache
									.setBackgroundResource(R.drawable.video_detail_cache_selector);
						} else {
							// 不能下载
							playerCache
									.setBackgroundResource(R.drawable.detail_icon_download_un);
						}
						tvFullProgress.setVisibility(View.VISIBLE);
						tvFullDuration.setVisibility(View.VISIBLE);
						tvSmallProgress.setVisibility(View.VISIBLE);
						tvSmallDuration.setVisibility(View.VISIBLE);
					}
					if (playerAdapter != null
							&& playerAdapter.getCurrentFrom() != null) {
						From curFrom = playerAdapter.getCurrentFrom();
						VideoPlayerMessage vmsg = new VideoPlayerMessage();
						vmsg.what = VideoPlayerMessage.MESSGAE_CHANGE_FROM;
						vmsg.obj = curFrom;
						EventBus.getDefault().post(vmsg);
						updateFromImage(curFrom);

						dfnt = curFrom.dfnt;
						if (playerAdapter.getVideoMode() == VideoMode.SERIES
								|| playerAdapter.getCurrentFrom().toply == 0) {// 剧集要获取播放记录中的集数的rst，直接播放
							String defaultDnf = SharedPreferenceModule
									.getInstance().getString(DEFINITION_KEY);
							if (TextUtils.isEmpty(defaultDnf)) {
								defaultDnf = "1";
							}
							if (TextUtils.isEmpty(dfnt)) {// 没有传过来清晰度
								requestVideoPlayUrl(
										playerAdapter.getXyzPlayUrl(), "1",
										"1", false);
							} else if (dfnt.contains(defaultDnf)) {
								requestVideoPlayUrl(
										playerAdapter.getXyzPlayUrl(), "1",
										defaultDnf, false);
							} else {
								requestVideoPlayUrl(
										playerAdapter.getXyzPlayUrl(), "1",
										dfnt.split(",")[0], false);
							}
						}

						if (playerAdapter.getCurrentFrom().toply == 0) {// 直接播放

							hideH5background();
							// 不固定竖屏
							if (action == PlayerAction.DETAIL
									&& !playerAdapter.isAirOneMode()) {
								changeOrientation(false, true);
							}
						} else {// 原网页播放
								// 显示播放按钮，到原网页播放背景
							action = PlayerAction.DETAIL;
							dismessProgressDialog();
							dismessLoadingDialog();
							btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
							btPlayFull
									.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
							if (playerAdapter.isAirOneMode()) {
								playerAdapter.stop();
							}
							playerAdapter.setPlayerRst(null, action);
							showOrHideSmallControlView(true);
							showH5background();
							// 固定竖屏
							changeOrientation(false, false);
						}
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_UPDATE_SUBTITLE:// 更新字幕
					tvSubtitle.setVisibility(View.VISIBLE);
					String mSubtitle = msg.obj.toString();
					if (mSubtitle != null) {
						L.v(TAG, mSubtitle);
						tvSubtitle.setText(mSubtitle.trim());
					} else {
						tvSubtitle.setText("");
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_UPDATE_SURFACEVIEW:// 设置SurfaceView宽高
					setSurfaceWidthHeight(msg.arg1, msg.arg2);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_SERIES_NEXT:// 剧集下一步
					XyzplaRst plaRst = playerAdapter.getPlaRst();
					requestVideoPlayUrl(plaRst.nexturl, "1", dfnt, true);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_AIRONE_OPEN_ERROR:
					dismessProgressDialog();
					Toast.makeText(FonePlayerActivity.this,
							R.string.airone_failed, Toast.LENGTH_SHORT).show();
					// airOnePlayingLayout.setVisibility(View.GONE);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_RESUME_PLAY_PROGRESS:// 恢复播放进度成功
					L.v(TAG, "FONE_PLAYER_MSG_RESUME_PLAY_PROGRESS progress = "
							+ msg.arg1);
					currentPostion = msg.arg1;
					mSeekBar_full.setMax(msg.arg2);
					mSeekBar_full.setProgress(msg.arg1);
					mSeekBar.setMax(msg.arg2);
					mSeekBar.setProgress(msg.arg1);
					tvFullProgress.setText(FoneUtil
							.second2MinuteStr(msg.arg1 / 1000));
					tvFullDuration.setText(FoneUtil
							.second2MinuteStr(msg.arg2 / 1000));
					tvSmallProgress.setText(FoneUtil
							.second2MinuteStr(msg.arg1 / 1000));
					tvSmallDuration.setText(FoneUtil
							.second2MinuteStr(msg.arg2 / 1000));
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_BUFFERING_PROGRESS:// 缓冲进度
					// 正在缓存
					if (FoneUtil.isNetOk(FonePlayerActivity.this)) {
						showProgressDialog(
								getString(R.string.video_loading_message)
										+ msg.arg1 + "%", false);
					} else {
						showProgressDialog(
								getString(R.string.video_loading_message),
								false);
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_BUFFERING_START:// 缓冲开始
					if (!mHandler
							.hasMessages(IPlayerAdapter.FONE_PLAYER_MSG_PLAY_TIMEOUT)) {
						mHandler.sendEmptyMessageDelayed(
								IPlayerAdapter.FONE_PLAYER_MSG_PLAY_TIMEOUT,
								IPlayerAdapter.PLAYER_PLAY_TIMEOUT_TIME);
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAY_TIMEOUT:// 超时，请返回重试
					Toast.makeText(FonePlayerActivity.this,
							R.string.fullplayer_media_buffer_timeout,
							Toast.LENGTH_LONG).show();
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_OPEN_FAILED:// 底层播放器打开失败，切换来源
					L.v(TAG, "player open failed!");
					// 如果已经Activity
					// 已经关闭了就不处理这个消息了，底层现在有一个bug，当省电加速播放状态退出播放时会发这个消息过来，所以暂时这样处理
					if (stop) {
						return;
					}
					videoSurface.setVisibility(View.INVISIBLE);
					if (msg.arg1 == 0) {
						L.v(TAG, "hardware plus open faild !");
						// 省电加速打开失败
						if (playerAdapter != null) {
							Toast.makeText(FonePlayerActivity.this,
									R.string.video_not_support_future,
									Toast.LENGTH_SHORT).show();
							playerAdapter.release();
							playerAdapter.play();
						}
						break;
					}
					Reporter.logError(
							FoneUtil.getCIdByUrl(xyzplay) == null ? ""
									: FoneUtil.getCIdByUrl(xyzplay),
							Reporter.ErrorType.LAUNCH_PLAYER_ERROR);// 打开播放器失败
					dismessProgressDialog();
					playerAdapter.stop();
					playerAdapter.release();
					updatePlayButton();
					playerAdapter.updatePlayRecord2MediaInfo();
					if (playerAdapter != null
							&& playerAdapter.getVideoMode() != VideoMode.LOCAL
							&& !FoneUtil
									.isNetOkWithToast(FonePlayerActivity.this)) {
						// 没有网络
						if (getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT) {
							// 显示播放按钮
							showOrHideSmallControlView(true);
						} else {
							// 解锁
							unlock();
						}
						break;
					}
					if (playerAdapter.getVideoDetail() != null) {
						// 重试3次
						if (replayTimes < 3) {
							playerAdapter.play();
							replayTimes++;
							return;
						}

						if (playerAdapter.getVideoDetail().froms.fromList
								.size() > currentFromIndex + 1) {
							// 切换来源:找到下一个来源
							currentFromIndex++;
							if (fromWindow != null) {
								fromWindow.setCurrentFrom(playerAdapter
										.getVideoDetail().froms.fromList
										.get(currentFromIndex));
							}
							playerAdapter.setCurrentFrom(playerAdapter
									.getVideoDetail().froms.fromList
									.get(currentFromIndex));
							break;
						}
					}
					Toast.makeText(FonePlayerActivity.this,
							R.string.player_open_failed, Toast.LENGTH_SHORT)
							.show();
					if (action == PlayerAction.DETAIL) {
						changeOrientation(false, false);
						fromWebViewHandler();
					} else {
						finish();
					}
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_AIRONE_NO_NEXT:// airone
					// 播放完成，没有下一集了
					// Toast.makeText(FonePlayerActivity.this,
					// R.string.player_no_next, Toast.LENGTH_SHORT).show();
					finish();
					break;
				case SHOW_UPDATE_DAILOG:// 显示升级对话框
					LoginRst rst = (LoginRst) msg.obj;
					L.v("测试", "handler 激活对话框");

					new UpdateDialog(mContext, FonePlayerActivity.this,
							rst.softupdate.updatedesc, UpdateDialog.SUGGEST,
							rst);

					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_SHOW_VIP_PAGE:// 弹出计费对话框
					dismessProgressDialog();
					String ccid = FoneUtil.getCCIdByUrl(playerAdapter
							.getXyzPlayUrl());
					String vipfrom = FoneConstants.FEE_FROM_VIP_PREFECTURE;
					switch (openFrom) {
					case SEARCH_ENTRANCE:
					case SEARCH_NORMAL:
						vipfrom = FoneConstants.FEE_FROM_SEARCH;
						break;
					case NOTIFICATION_INTERNAL:
					case NOTIFICATION_EXTERNAL:
						vipfrom = FoneConstants.FEE_FROM_PUSH;
						break;
					case FAST_PLAY_ONLINE:
						vipfrom = FoneConstants.FEE_FROM_FAST_PLAY;
						break;
					default:
						break;
					}
					FonePayManager.getInstance().startPay(
							FoneConstants.DO_VIP_ACTION,
							FoneConstants.FROM_VIP_FILM, vipfrom, ccid);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_AIRONE_TRANSLATION:// airone正在打开
					showProgressDialog(null, true);
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_VIDEO_OUT_LINE_TOAST:// 视频暂时无法播放
					if (playerAdapter.isCacheVideo()) {
						Reporter.logError(
								FoneUtil.getCIdByUrl(xyzplay) == null ? ""
										: FoneUtil.getCIdByUrl(xyzplay),
								Reporter.ErrorType.CACHE_PLAY_ERROR);// 缓存播放失败
					} else if (playerAdapter.getVideoMode() != VideoMode.LOCAL) {
						Reporter.logError(
								FoneUtil.getCIdByUrl(xyzplay) == null ? ""
										: FoneUtil.getCIdByUrl(xyzplay),
								Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
					}
					Toast.makeText(FonePlayerActivity.this,
							R.string.video_outline_text, Toast.LENGTH_SHORT)
							.show();
					break;
				case IPlayerAdapter.FONE_PLAYER_MSG_PLAYER_OPEN_SUCCESS:// 播放器打开成功
					updateMediaDuring();
					break;
				case UPDATE_TIME_MESSAGE:// 更新全屏播放显示的时间
					// 显示最新时间
					fullSystemTime.setText(FoneUtil.formatDate(new Date(),
							"HH:mm"));
					sendEmptyMessageDelayed(UPDATE_TIME_MESSAGE, 1000);
					break;
				default:
					break;
				}
			}

		};
	}

	/**
	 * 更新播放按钮
	 * 
	 * @return void
	 * @throws
	 */
	protected void updatePlayButton() {
		L.v(TAG, "updatePlayButton isplaying = " + playerAdapter.isPlaying());
		btPlay.setBackgroundResource(playerAdapter.isPlaying() ? R.drawable.video_detail_pause_selector
				: R.drawable.video_detail_play_selector);
		btPlayFull
				.setBackgroundResource(playerAdapter.isPlaying() ? R.drawable.video_fullscreen_pause_selector
						: R.drawable.video_fullscreen_play_selector);
	}

	/**
	 * 初始化View
	 */
	@SuppressWarnings("deprecation")
	private void initViews() {
		btPlay = (Button) findViewById(R.id.play_small);
		h5bg = (ImageView) findViewById(R.id.h5_bg);
		mSeekBar = (SeekBar) findViewById(R.id.seekbar_small);
		mSeekBar_full = (SeekBar) findViewById(R.id.full_player_seekbar);
		btPlayFull = (Button) findViewById(R.id.full_player_play_pause);
		videoSurface = (SurfaceView) findViewById(R.id.videoSV);
		fullIB = (ImageButton) findViewById(R.id.fullscreen_button);
		infoLayout = findViewById(R.id.videoinfo_layout);
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
			videoSurface.getHolder().setType(SurfaceHolder.SURFACE_TYPE_NORMAL); // 如果在2.3或更低版本的设备上使用,
		}
		videoSurface.getHolder().addCallback(new SurfaceViewCallback()); // 监听SurfaceView的摧毁和重构事件
		mPlayerGestureView = (FoneGestureOverlayView) findViewById(R.id.full_surface_gesture);
		mPlayerGestureView.setVisibility(View.INVISIBLE);
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		pager = (ViewPager) findViewById(R.id.pager);
		mFullLayout = findViewById(R.id.player_fullscreen_layout);
		mTitlebarSmall = findViewById(R.id.player_title_bar_small_layout);
		mFullRightLayout = findViewById(R.id.full_player_right);
		mFullRightSeriesRecommend = findViewById(R.id.full_player_show_series_recommend_layout);
		mFullRecommend = (Button) findViewById(R.id.full_player_recommend);
		mFullSeries = (Button) findViewById(R.id.full_player_select_series);
		mBtAirone = (Button) findViewById(R.id.player_full_airone);
		surfaceLayout = (RelativeLayout) findViewById(R.id.video_surface_layout);
		fullMore = (Button) findViewById(R.id.full_player_menu);
		moreMenuLayout = findViewById(R.id.full_player_menu_layout);
		moreMenuItems.add((TextView) findViewById(R.id.video_full_3d));
		moreMenuItems.add((TextView) findViewById(R.id.video_full_track));
		moreMenuItems.add((TextView) findViewById(R.id.video_full_subtitle));
		moreMenuItems.add((TextView) findViewById(R.id.video_full_speed));
		moreMenuItems.add((TextView) findViewById(R.id.video_full_hwplus));
		genstureLayout = findViewById(R.id.full_player_gensture_layout);
		soundBrightLayout = findViewById(R.id.video_full_vol_layout);
		ivSoundBright = (ImageView) findViewById(R.id.video_full_vol_icon);
		tvSoundBright = (TextView) findViewById(R.id.video_full_vol_text);
		tvGestureProgress = (TextView) findViewById(R.id.video_full_postion_text);
		tvFullDuration = (TextView) findViewById(R.id.full_player_play_duration);
		tvFullProgress = (TextView) findViewById(R.id.full_player_play_progress);
		btBackSmall = (Button) findViewById(R.id.player_back);
		btFullBack = (Button) findViewById(R.id.player_back_full);
		btLock = (Button) findViewById(R.id.player_full_lock);
		mFullTitleBar = findViewById(R.id.full_player_titlebar);
		mFullLeft = findViewById(R.id.full_player_left);
		mFullContorlBar = findViewById(R.id.full_player_control_bar);
		mFullRight = findViewById(R.id.full_player_right);
		mTitleSmall = (TextView) findViewById(R.id.player_title);
		mTitleFull = (AutoFocusTextView) findViewById(R.id.player_title_full);
		mFullDefinition = (Button) findViewById(R.id.full_player_definition);
		fullPlayerNext = (Button) findViewById(R.id.full_player_next);
		playerCollection = (Button) findViewById(R.id.player_collection);
		playerCache = (Button) findViewById(R.id.player_cache);
		playerShare = (Button) findViewById(R.id.player_share);
		videoSeriesCacheLayout = findViewById(R.id.player_video_series_cache_layout);
		videoSeriesCacheCancel = (Button) findViewById(R.id.video_series_cache_button_cancel);
		videoSeriesCacheOk = (Button) findViewById(R.id.video_series_cache_button_ok);
		fullPlayerLinkList = (ListView) findViewById(R.id.full_player_recommend_list);
		fullPlayerRuleSeriesLayout = findViewById(R.id.full_player_rule_series_layout);
		airOnePlayingLayout = findViewById(R.id.full_player_airone_playing_layout);
		playSmallControlLayout = findViewById(R.id.play_small_control_layout);
		fromLayout = findViewById(R.id.player_form_layout);
		fromIcon = (ImageView) findViewById(R.id.player_form_icon);
		tvSubtitle = (TextView) findViewById(R.id.full_player_subtitle_text);
		ruleSeriesPagerGrid = (GridView) findViewById(R.id.full_player_rule_series_pager_gridview);
		ruleSeriesItemGrid = (GridView) findViewById(R.id.full_player_rule_series_item_gridview);
		videoSeriesCachePager = (NoScrollGridView) findViewById(R.id.cache_gridview_tab);
		ruleVideoSeriesCacheGridView = (GridView) findViewById(R.id.cache_tv_gv);
		unRuleVideoSeriesCacheList = (ListView) findViewById(R.id.cache_tv_lv);
		videoSeriesCacheRuleLayout = findViewById(R.id.video_series_cache_gridmode_layout);
		videoSeriesCacheUnRuleLayout = findViewById(R.id.video_series_cache_listmode_layout);
		cacheProgress = (ColorBallProgressView) findViewById(R.id.video_series_cache_progress);
		tvSmallProgress = (TextView) findViewById(R.id.play_progress_small);
		tvSmallDuration = (TextView) findViewById(R.id.play_duration_small);
		requestProgress = (ColorBallProgressView) findViewById(R.id.play_loading);
		loadingMessage = (TextView) findViewById(R.id.play_loading_message);
		fullRuleSeriesPagerHorizontalSV = (EnhanceHorizontalScrollView) findViewById(R.id.full_player_series_cache_page_hsv);
		batteryStatus = (ImageView) findViewById(R.id.player_battery_full);
		fullSystemTime = (TextView) findViewById(R.id.player_time_full);
	}

	/**
	 * 显示/隐藏控制区
	 * 
	 * @param isShow
	 *            是否显示
	 * @return void
	 * @throws
	 */
	public void showOrHideSmallControlView(boolean isShow) {
		// 原网页播放的视频不隐藏播放按钮了
		if (!isShow && playerAdapter.getCurrentFrom() != null
				&& playerAdapter.getCurrentFrom().toply == 1) {
			return;
		}
		playSmallControlLayout.setVisibility(isShow ? View.VISIBLE : View.GONE);
		btPlay.setVisibility(isShow ? View.VISIBLE : View.GONE);
	}

	private Runnable hideSmallControlViewRun = new Runnable() {

		@Override
		public void run() {
			showOrHideSmallControlView(false);
		}
	};

	/**
	 * 切换大屏时隐藏小屏的一些view
	 * 
	 * @return void
	 * @throws
	 */
	private void invalidateViewChange2Land() {
		btPlay.setVisibility(View.GONE);
		playSmallControlLayout.setVisibility(View.GONE);
		fullIB.setVisibility(View.GONE);
		infoLayout.setVisibility(View.GONE);
		mTitlebarSmall.setVisibility(View.GONE);
		mPlayerGestureView.setVisibility(View.VISIBLE);
		mFullLayout.setVisibility(View.VISIBLE);
		if (fromWindow != null && fromWindow.isShowing()) {
			fromWindow.dismiss();
		}
		showFullScreenLayout();
		hideSharePopWindow();
	}

	/**
	 * 切换回小屏时显示小屏的一些View
	 * 
	 * @return void
	 * @throws
	 */
	private void invalidateViewChange2Port() {
		if (!buffering) {
			btPlay.setVisibility(View.VISIBLE);
		}
		playSmallControlLayout.setVisibility(View.VISIBLE);
		fullIB.setVisibility(View.VISIBLE);
		infoLayout.setVisibility(View.VISIBLE);
		mTitlebarSmall.setVisibility(View.VISIBLE);
		mPlayerGestureView.setVisibility(View.INVISIBLE);
		mFullLayout.setVisibility(View.GONE);
		hideSecondMenu();
		moreMenuLayout.setVisibility(View.INVISIBLE);
	}

	/**
	 * 显示缓冲圆形进度条
	 * 
	 * @param msg
	 *            进度条文字
	 * @param isAirone
	 *            是否airone进度条
	 */
	private void showProgressDialog(String msg, boolean isAirone) {
		if (!isAirone && playerAdapter != null
				&& playerAdapter.getVideoMode() == VideoMode.LOCAL) {
			return;
		}
		if (genstureLayout.getVisibility() == View.VISIBLE) {
			genstureLayout.setVisibility(View.GONE);
		}
		showOrHideSmallControlView(false);
		buffering = true;
		if (requestProgress.getVisibility() != View.VISIBLE) {
			requestProgress.setVisibility(View.VISIBLE);
			loadingMessage.setVisibility(View.VISIBLE);
		}
		if (!TextUtils.isEmpty(msg)) {
			loadingMessage.setText(msg);
		}
		// setSeekBarEnable(!buffering);
	}

	/**
	 * 隐藏进度条
	 * 
	 * @return void
	 * @throws
	 */
	private void dismessProgressDialog() {
		buffering = false;
		if (requestProgress != null
				&& requestProgress.getVisibility() == View.VISIBLE) {
			loadingMessage.setVisibility(View.GONE);
			requestProgress.setVisibility(View.GONE);
		}
		// setSeekBarEnable(!buffering);
	}

	/**
	 * 显示加载对话框
	 * 
	 * @return void
	 * @throws
	 */
	private void showLoadingDialog() {
		if (loadingDialog == null) {
			// com_waiting_dialog
			loadingDialog = new Dialog(FonePlayerActivity.this,
					R.style.comm_alertdialog);
			loadingDialog.setContentView(R.layout.com_waiting_dialog);
			loadingDialog.setCancelable(false);
			loadingDialog.setCanceledOnTouchOutside(false);
			loadingDialog.setOnKeyListener(new OnKeyListener() {
				@Override
				public boolean onKey(DialogInterface dialog, int keyCode,
						KeyEvent event) {
					onBackPressed();
					return false;
				}
			});
		}
		if (!loadingDialog.isShowing()) {
			loadingDialog.show();
		}
	}

	/**
	 * 隐藏加载对话框
	 * 
	 * @return void
	 * @throws
	 */
	private void dismessLoadingDialog() {
		if (!stop && loadingDialog != null && loadingDialog.isShowing()) {
			loadingDialog.dismiss();
		}
	}

	/**
	 * 更新视频长度
	 * 
	 * @return void
	 * @throws
	 */
	private void updateMediaDuring() {
		L.v(TAG, "updateMediaDuring");
		int duration = playerAdapter.getMediaDuration();
		if (duration > 0 && mSeekBar.getMax() != duration) {
			mSeekBar.setMax(duration); // 获取媒体文件的持续时间,
			mSeekBar_full.setMax(duration); // 获取媒体文件的持续时间,
			L.v(TAG, "updateMediaDuring currentPostion = " + currentPostion);
			mHandler.post(new Runnable() {
				@Override
				public void run() {
					tvFullDuration.setText(FoneUtil.second2MinuteStr(Math
							.round((float) playerAdapter.getMediaDuration() / 1000f)));
					tvSmallDuration.setText(FoneUtil.second2MinuteStr(Math
							.round((float) playerAdapter.getMediaDuration() / 1000f)));
				}
			});
		}
	}

	/**
	 * 进度条更新线程
	 * 
	 * @author kongxiaojun
	 * @since 2014-4-16
	 * 
	 */
	private class SeekBarThread extends Thread {

		private boolean stop;

		public void run() {
			try {
				Thread.sleep(1000);
				while (!stop && playerAdapter != null) {
					L.v(TAG, "SeekBarThread running");
					// 解决有声音无画面的bug
					if (!playerAdapter.isAirOneMode() && videoSurface != null
							&& videoSurface.getVisibility() != View.VISIBLE) {
						mHandler.post(new Runnable() {
							@Override
							public void run() {
								videoSurface.setVisibility(View.VISIBLE);
							}
						});
					}

					if (playerAdapter.isLiveVideo()) {// 直播没有进度
						mHandler.post(new Runnable() {
							@Override
							public void run() {
								L.v(TAG,
										"SeekBarThread isLiveVideo reset seekbar");
								mSeekBar.setMax(1000);
								mSeekBar_full.setMax(1000);
								mSeekBar.setProgress(0); // 设置进度条的进度为当前播放进度
								mSeekBar_full.setProgress(0); // 设置进度条的进度为当前播放进度
								mSeekBar.setEnabled(false);
								mSeekBar_full.setEnabled(false);
							}
						});

					} else if (playerAdapter.isPlaying()
							&& !gestureChangeProgress) {

						currentPostion = playerAdapter.getCurrentPosition();
						if (currentPostion > playerAdapter.getMediaDuration()) {
							currentPostion = playerAdapter.getMediaDuration();
						}
						if (currentPostion > 0) {
							mHandler.post(new Runnable() {
								@Override
								public void run() {
									L.v(TAG, "SeekBarThread update postion = "
											+ currentPostion);
									mSeekBar.setProgress(currentPostion); // 设置进度条的进度为当前播放进度
									mSeekBar_full.setProgress(currentPostion); // 设置进度条的进度为当前播放进度
									if (!mSeekBar.isEnabled()) {
										mSeekBar.setEnabled(true);
										mSeekBar_full.setEnabled(true);
									}
									tvFullProgress.setText(FoneUtil.second2MinuteStr(Math
											.round((float) currentPostion / 1000f)));
									tvSmallProgress.setText(FoneUtil.second2MinuteStr(Math
											.round((float) currentPostion / 1000f)));
								}
							});
						}
					} else if (gestureChangeProgress) {
						Thread.sleep(1000);
					}
					if (playerAdapter != null && !playerAdapter.isAirOneMode()
							&& playerAdapter.getCurrentRate() > 1) {
						Thread.sleep(500);
					} else {
						Thread.sleep(1000);
					}
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		public void setStop(boolean stop) {
			this.stop = stop;
		}

	}

	/**
	 * SurfaceView状态改变的回调类
	 * 
	 * @author kongxiaojun
	 * @since 2014-4-18
	 * 
	 */
	private class SurfaceViewCallback implements Callback {
		public void surfaceDestroyed(SurfaceHolder holder) { // 被切换到后台时, 自动摧毁
			L.v(TAG, "surfaceDestroyed");
			surfaceCreated = false;
			if (playerAdapter != null && !playerAdapter.isAirOneMode()
					&& !playerAdapter.isSeeking()
					&& !playerAdapter.isSystemPlayerOpenFailed()
					&& playerAdapter.isOpenSuccess()) {
				L.v(TAG, "wwb_message  call stop and release");
				playerAdapter.stop();
				playerAdapter.release();
				// 解决切换来源后未继续上次的时间播放
				if (!isChangeFrom) {
					playerAdapter.updatePlayRecord2MediaInfo();
				} else {
					isChangeFrom = false;
				}
			} else if (playerAdapter != null
					&& playerAdapter.isSystemPlayerOpenFailed()) {
				playerAdapter.setSystemPlayerOpenFailed(false);
			}
			btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
			btPlayFull
					.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
		}

		public void surfaceCreated(SurfaceHolder holder) { // 从后台切换到前台时, 重新创建
			L.v(TAG, "surfaceCreated");
			surfaceCreated = true;
			if (playerAdapter != null) {
				playerAdapter.setSurfaceView(holder);
			}
		}

		public void surfaceChanged(SurfaceHolder holder, int format, int width,
				int height) {
		}
	}

	public void doChangeOrientation(View v) {
		doChangeOrientation(false);
	}

	/**
	 * 播放
	 * 
	 * @param v
	 *            播放按钮
	 */
	public void play() {
		L.v(TAG, "play");
		if (action == PlayerAction.DETAIL
				&& playerAdapter.getCurrentFrom() != null
				&& playerAdapter.getCurrentFrom().toply == 1) {
			// 去原网页
			go3rdPlayer();
			return;
		}

		if (playerAdapter == null) {
			initPlayerAdapter();
		}
		if (playerAdapter.isPlaying() && !playerAdapter.isLiveVideo()) {
			playerAdapter.pause();
		} else {
			playerAdapter.play();
		}
	}

	/**
	 * 去原网页播放
	 * 
	 * @return void
	 * @throws
	 */
	private void go3rdPlayer() {
		if (FoneUtil.isNetOkWithToast(FonePlayerActivity.this)) {

			// 处理sohu视频
			String ourl;
			if (playerAdapter.getPlaRst() != null) {
				ourl = playerAdapter.getPlaRst().cnt.ourl;
			} else {
				ourl = playerAdapter.getCurrentFrom().ourl;
			}

			if (ourl.contains("sohu.com")) {// sohu
				doSohuPlayer(ourl);
				return;
			} else if (ourl.contains("letv.com")) {// 乐视
				if (doLetvPlayer(ourl)) {
					return;
				}
			}

			Intent intent = new Intent(FonePlayerActivity.this,
					WebViewPlayerActivity.class);
			intent.putExtra("xyzplay", playerAdapter.getXyzPlayUrl());
			intent.putExtra("from", WebPlayerFrom.DETAIL.toString());
			if (playerAdapter.getPlaRst() != null) {
				intent.putExtra("ourl", playerAdapter.getPlaRst().cnt.ourl);
				intent.putExtra("btnply", playerAdapter.getPlaRst().cnt.btnply);
				intent.putExtra("weibourl", playerAdapter.getPlaRst().weibourl);
			} else {
				intent.putExtra("ourl", playerAdapter.getCurrentFrom().ourl);
				intent.putExtra("btnply", playerAdapter.getCurrentFrom().btnply);
				intent.putExtra("weibourl",
						playerAdapter.getCurrentFrom().weibourl);
			}
			if (!TextUtils.isEmpty(playerAdapter.getVideoDetail().pic)) {
				intent.putExtra("pic",
						FoneUtil.formatUrl(playerAdapter.getVideoDetail().pic));
			}
			intent.putExtra("name", playerAdapter.getVideoName());
			startActivity(intent);
		}
	}

	/**
	 * 初始化乐视SDK
	 * 
	 * @return void
	 * @throws
	 */
	private void initLetvSDK() {
		LetvSdk.getInstance().setConetxt(this);// 设置context
		LetvSdk.getInstance().registerCallBack(
				new com.letv.sdk.onehundredtv.video.BDVideoPartner.Callback() {
					@Override
					public void onEvent(final int event, final String name,
							IVideo video) {
						// 播放器回调
						if (event == BDVideoPartner.EVENT_PLAY_START) {
						} else if (event == BDVideoPartner.EVENT_DLNA_PLAY) {
						} else if (event == BDVideoPartner.EVENT_PLAY_PAUSE) {
						} else if (event == BDVideoPartner.EVENT_PLAY_STOP) {// 播放器退出
						} else if (event == BDVideoPartner.EVENT_PLAY_RESUME) {
						} else if (event == BDVideoPartner.EVENT_PLAY_NEXT) {
						} else if (event == BDVideoPartner.EVENT_PLAY_PREV) {
						} else if (event == BDVideoPartner.EVENT_FAVORITE) {// 收藏
						} else if (event == BDVideoPartner.EVENT_FAVORITE_CANCEL) {// 取消收藏
						} else if (event == BDVideoPartner.EVENT_START_DOWNLOAD) {// 下载
							// 下载地址获取地方
							LetvSdk.getInstance().changeDownState(1);// 0是下载
																		// 1是已下载
							// Toast.makeText(FonePlayerActivity.this,
							// "该vid的下载地址为  ：" +
							// video.mDownloadUrl, Toast.LENGTH_SHORT).show();
						} else if (event == BDVideoPartner.EVENT_PLAY_PREV) {

						}
					}
				});// 注册回调
	}

	/**
	 * 乐视SDK播放
	 * 
	 * @param ourl
	 * @return boolean 调用乐视sdk是否成功
	 * @throws
	 */
	private boolean doLetvPlayer(String ourl) {
		// 保存播放记录
		save3rdPlayRecord();
		// 截取ourl中的vid
		long vid = FoneUtil.getLetvVidByUrl(ourl);
		if (vid == 0) {
			// 调用乐视sdk失败
			return false;
		} else {
			IVideo video1 = new IVideo();
			video1.vID = vid;// 只有vid
			video1.mCurrentTime = 0;// 设置播放进度 单位s
			video1.mIsFavorite = true;
			video1.mDownloadStatus = IVideo.DOWNLOAD_NONE;
			LetvSdk.getInstance().play(FonePlayerActivity.this, video1);
			return true;
		}
	}

	/**
	 * 搜狐sdk播放
	 * 
	 * @param ourl
	 *            搜狐源地址
	 * @return void
	 * @throws
	 */
	private void doSohuPlayer(String ourl) {
		// 保存播放记录
		save3rdPlayRecord();
		// 搜狐来源
		FoneUtil.openSohuPlayer(FonePlayerActivity.this, "111", "100tv", ourl);
	}

	/**
	 * 保存第三方播放记录
	 * 
	 * @return void
	 * @throws
	 */
	private void save3rdPlayRecord() {
		String ourl = null;
		int btnply;
		String weibourl = null;
		if (playerAdapter.getPlaRst() != null) {
			ourl = playerAdapter.getPlaRst().cnt.ourl;
			btnply = playerAdapter.getPlaRst().cnt.btnply;
			weibourl = playerAdapter.getPlaRst().weibourl;
		} else {
			ourl = playerAdapter.getCurrentFrom().ourl;
			btnply = playerAdapter.getCurrentFrom().btnply;
			weibourl = playerAdapter.getCurrentFrom().weibourl;
		}
		FoneUtil.save3rdRecord(playerAdapter.getXyzPlayUrl(), ourl, btnply,
				weibourl, playerAdapter.getVideoDetail().pic,
				playerAdapter.getVideoName());
	}

	/**
	 * 进度条改变监听
	 * 
	 * @author kongxiaojun
	 * @since 2014-4-16
	 * 
	 */
	private class FoneOnSeekBarChangeListener implements
			OnSeekBarChangeListener {
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
		}

		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		public void onStopTrackingTouch(SeekBar seekBar) {
			if (!buffering && playerAdapter != null) {
				sendHidePlayerControlLayoutHander();
				if (playerAdapter.getMediaDuration() > 0) {
					tvFullProgress
							.setText(FoneUtil.second2MinuteStr(Math
									.round((float) mSeekBar_full.getProgress() / 1000f)));
					tvSmallProgress
							.setText(FoneUtil.second2MinuteStr(Math
									.round((float) mSeekBar_full.getProgress() / 1000f)));
					playerAdapter.seekTo(seekBar.getProgress()); // 把播放器调整到进度条的位置
					showProgressDialog(
							getString(R.string.video_loading_message), false);
				}
			}
		}
	}

	/**
	 * 更新时间
	 * 
	 * @return void
	 * @throws
	 */
	private void startUpdateTime() {
		if (mHandler != null) {
			mHandler.sendEmptyMessageDelayed(UPDATE_TIME_MESSAGE, 1000);
		}
	}

	/**
	 * 初始化电池电量接收
	 * 
	 * @return void
	 * @throws
	 */
	private void initBatteryReceiver() {
		batteryReceiver = new BatteryReceiver();
		IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
		registerReceiver(batteryReceiver, filter);
	}

	/**
	 * 电池电量广播接收者
	 * 
	 * @author kongxiaojun
	 * @since 2014-9-2
	 */
	private class BatteryReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			// 判断它是否是为电量变化的Broadcast Action
			if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
				// 获取当前电量
				int level = intent.getIntExtra("level", 0);
				// 电量的总刻度
				int scale = intent.getIntExtra("scale", 100);
				// 电池状态
				int status = intent.getIntExtra("status", -1);
				// 把它转成百分比
				// tv.setText("电池电量为"+((level*100)/scale)+"%");
				switch (status) {
				case BatteryManager.BATTERY_STATUS_CHARGING: {// 充电中
					batteryStatus
							.setImageResource(R.drawable.player_batter_charging);
					break;
				}
				default: {
					// 计算电池电量百分比显示对应的状态图
					int percentage = (level * 100) / scale;
					if (percentage > 75) {
						// 显示满格
						batteryStatus
								.setImageResource(R.drawable.player_battery_full);
					} else if (percentage > 35) {
						// 显示中格
						batteryStatus
								.setImageResource(R.drawable.player_battery_middle);
					} else {
						// 显示低电量
						batteryStatus
								.setImageResource(R.drawable.player_battery_low);
					}
					break;
				}
				}
			}
		}

	}

	@Override
	protected void onStop() {
		stop = true;
		// if (playerAdapter != null && playerAdapter.isAirOneMode()) {
		// playerAdapter.stop();
		// playerAdapter.release();
		// btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
		// btPlayFull.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
		// }
		//
		dismessProgressDialog();
		if (playerAdapter != null && playerAdapter.isOpenSuccess()) {
			playerAdapter.stop();
			playerAdapter.release();
			playerAdapter.updatePlayRecord2MediaInfo();
			if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
				showFullScreenLayout();
			} else {
				showOrHideSmallControlView(true);
			}
			videoSurface.setVisibility(View.INVISIBLE);
			mHandler.removeCallbacks(hideSmallControlViewRun);
			mHandler.removeCallbacks(hideFullScreenLayoutRunnable);
			btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
			btPlayFull
					.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
		}

		if (mSeekBarThread != null) {
			mSeekBarThread.interrupt();
		}
		mSeekBarThread = null;

		super.onStop();
	}

	@Override
	protected void onDestroy() {
		L.v(TAG, "onDestroy");
		super.onDestroy();
		playerAdapter.setPlayerRelease(true);
		playerAdapter.stop();
		playerAdapter.release();
		playerAdapter = null; // 垃圾回收
		AirOne.Stop();
		disableOrientationEventListener();
		unregisterReceiver(batteryReceiver);
		mPlayerGestureView.removeAllOnGestureListeners();
		if (FonePlayerActivityInstance != null) {
			FonePlayerActivityInstance.clear();
		}
		eventReceiver.destory(this);
		eventReceiver = null;
		mHandler.removeCallbacksAndMessages(null);
		mHandler = null;
		L.v(TAG, "onDestroy",
				"start startAllCache MSG_ACTION_OPERATE_PROGRAM_TYPE");
		// 开始所有暂停的下载任务
		StorageModule.getInstance().startAllCache();
		EventBus.getDefault().unregister(this);
		destoryResource();
	}

	private void destoryResource() {
		if (mListener != null) {
			mListener.disable();
		}
		if (seriesModeAdapter != null) {
			seriesModeAdapter.destory();
		}
		seriesModeAdapter = null;
		liveModeAdapter = null;
		shortModeAdapter = null;
		singleModeAdapter = null;
		videoDetail = null;
		mListener.disable();
		mListener = null;
	}

	/**
	 * 初始化屏幕方向监听器
	 */
	private void initOrientationEventListener() {
		mListener = new OrientationEventListener(
				ApplicationManage.getAplicationManageInstance(),
				SensorManager.SENSOR_DELAY_UI) {
			public void onOrientationChanged(int orientation) {
				L.v(TAG, "onOrientationChanged", orientation);
				if (mReverse) {
					if ((orientation > 0 && orientation < 30)
							|| (orientation > 330 && orientation < 360)) {
						if (FonePlayerActivity.this.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
							FonePlayerActivity.this
									.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
						}
					} else if ((orientation > 90 && orientation < 120)
							|| (orientation > 240 && orientation < 270)) {
						if (FonePlayerActivity.this.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
								|| FonePlayerActivity.this
										.getRequestedOrientation() == 6) {
							FonePlayerActivity.this
									.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
						}
					}
				}
			}
		};
	}

	@Override
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);

		// 检测屏幕的方向：纵向或横向
		if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
			// 当前为横屏， 在此处添加额外的处理代码
			L.i(TAG, "onConfigurationChanged", "ORIENTATION_LANDSCAPE");

			this.getWindow().setFlags(
					WindowManager.LayoutParams.FLAG_FULLSCREEN,
					WindowManager.LayoutParams.FLAG_FULLSCREEN);

		} else if (getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT) {
			// 当前为竖屏， 在此处添加额外的处理代码
			L.i(TAG, "onConfigurationChanged", "ORIENTATION_PORTRAIT");
			WindowManager.LayoutParams attrs = this.getWindow().getAttributes();
			attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
			this.getWindow().setAttributes(attrs);
			this.getWindow().clearFlags(
					WindowManager.LayoutParams.FLAG_FULLSCREEN);
		}

		if (mReverse) {
			mListener.enable();
		} else {
			mListener.disable();
		}

		onChangedOrientation(getScreenOrientation());

	}

	/**
	 * 屏幕方向翻转
	 * 
	 * @param reverse
	 *            是否还支持感应器翻转
	 */
	public void doChangeOrientation(boolean reverse) {
		int orientation = getScreenOrientation();
		if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
			changeOrientation(false, reverse);
			L.v("测试", "方向切换-->横屏切竖屏");
		} else {
			changeOrientation(true, reverse);
			L.v("测试", "方向切换-->竖屏切横屏");
		}
	}

	/**
	 * 屏幕方向翻转
	 * 
	 * @param reverse
	 *            是否还支持感应器翻转
	 */
	public void changeOrientation(boolean isLandscape, boolean reverse) {
		if (!reverse) {
			mListener.disable();
		} else {
			mListener.enable();
		}
		mReverse = reverse;
		if (isLandscape) {
			if (android.os.Build.VERSION.SDK_INT >= 9) {
				setRequestedOrientation(6); // ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
			} else {
				setRequestedOrientation(0); // ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
			}
		} else {
			hideAirOnePlayingLayout();
			if (mReverse) {
				this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);// 感应器
			} else {
				this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 锁定竖屏
			}
		}
	}

	/**
	 * 横竖屏切换执行的操作
	 */
	public void onChangedOrientation(int orientation) {
		if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
			invalidateViewChange2Land();
			// surface view 全屏
			surfaceLayout.getLayoutParams().height = LayoutParams.FILL_PARENT;
			surfaceLayout.getLayoutParams().width = LayoutParams.FILL_PARENT;
			if (FoneConstant.loginRst != null
					&& FoneConstant.loginRst.softupdate.position == 1) {
				isCancel = true;
			}
			if (!FoneConstant.isUpdate && !isTimeing) {
				initUpdate();
			}
		} else {
			invalidateViewChange2Port();
			surfaceLayout.getLayoutParams().height = (int) getResources()
					.getDimension(R.dimen.video_detaile_surface_view_height);
			surfaceLayout.getLayoutParams().width = LayoutParams.FILL_PARENT;
			LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,
					LayoutParams.FILL_PARENT);
			videoSurface.setLayoutParams(params);
			mFullRightSeriesRecommend.setVisibility(View.GONE);
			L.v("测试", "方向切换-->竖屏");
			if (FoneConstant.loginRst != null
					&& FoneConstant.loginRst.softupdate.position == 2) {
				L.v("测试", "中断全屏升级！");
				isCancel = true;
			}
			if (!FoneConstant.isUpdate && !isTimeing) {
				initUpdate();
			}
		}
		sendHidePlayerControlLayoutHander();
		playerAdapter.onChangedOrientation(orientation);
	}

	/**
	 * 禁用屏幕方向监听
	 */
	public void disableOrientationEventListener() {
		if (mListener != null) {
			mListener.disable();
		}
	}

	/**
	 * 启用屏幕方向监听
	 */
	public void enableOrientationEventListener() {
		if (mListener != null) {
			mListener.enable();
		}
	}

	/**
	 * 是否有新的intent
	 */
	private boolean hasNewIntent = false;

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		L.v(TAG, "onNewIntent");
		hasNewIntent = true;
		vgdetail = null;
		xyzplay = null;
		handNewIntent(intent);
	}

	@Override
	protected void onRestart() {
		super.onRestart();
		L.v(TAG, "onRestart");
		if (!hasNewIntent) {
			updateData();
			L.v(TAG, "onRestart hasNewIntent == false");
			if (action == PlayerAction.DETAIL
					&& playerAdapter.getCurrentFrom() != null
					&& playerAdapter.getCurrentFrom().toply == 1) {// 原网页不视频不播放
				return;
			}
			if (playerAdapter != null && playerAdapter.isVip()
					&& !UserInfoManager.isVip()) {
				return;
			} else if (playerAdapter != null && playerAdapter.isVip()
					&& UserInfoManager.isVip()) {
				playerAdapter.updatePlayRecord2MediaInfo();
			}
			if (playerAdapter.getVideoMode() != VideoMode.LOCAL
					&& playerAdapter.getPlaRst() == null) {
				if (!requestVideoInfo && !TextUtils.isEmpty(vgdetail)) {
					requestVideoDetail(vgdetail);
					return;
				}
			}
			if (playerAdapter.isOpenSuccess()) {
				playerAdapter.play();
			}

		} else {
			L.v(TAG, "onRestart hasNewIntent == true");
			hasNewIntent = false;
		}
	}

	public void handNewIntent(Intent intent) {
		L.v(TAG, "handNewIntent");
		playerAdapter.stop();
		playerAdapter.release();
		videoSurface.setVisibility(View.INVISIBLE);
		hideAirOnePlayingLayout();
		playerAdapter = null;
		seriesRst = null;
		if (pager != null) {
			pager.removeAllViews();
		}
		initPlayerAdapter();
		handleIntent(intent);
	}

	/**
	 * 处理intent
	 * 
	 * @param intent
	 *            传递过来的intent
	 */
	private void handleIntent(Intent intent) {
		openFrom = intent.getIntExtra("from", 0);

		playerAdapter.setComeFrom(openFrom);
		hideH5background();
		if (fromWindow != null && fromWindow.isShowing()) {
			fromWindow.dismiss();
		}
		fromWindow = null;
		if (openFrom == THIRDPARTY) {// 来自一个url或者文件管理器
			Reporter.logLocalPlay(5);
			Reporter.start();

			action = PlayerAction.FULLPLAY;
			changeOrientation(true, false);
			Uri uriPath = intent.getData();
			try {
				if (null != uriPath) {
					String scheme = uriPath.getScheme();
					String url;
					if (null != scheme) {
						url = URLDecoder.decode(uriPath.toString(), "utf-8");
					} else {
						url = URLDecoder.decode(uriPath.getPath(), "utf-8");
					}
					if (TextUtils.isEmpty(url)) {
						Toast.makeText(FonePlayerActivity.this,
								R.string.player_error_url_null,
								Toast.LENGTH_SHORT).show();
						finish();
					} else {
						playerAdapter.playUrl(0, url);
						playerAdapter.setEncryption(false);
					}
				} else {
					Toast.makeText(FonePlayerActivity.this,
							R.string.player_error_url_null, Toast.LENGTH_SHORT)
							.show();
					finish();
				}
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			}
		} else {
			// 来自100tv客户端
			if (openFrom == WEBVIEW) {// 是否来自原网页
				playerAdapter.setFromWebView(true);
			} else if (openFrom == NOTIFICATION_EXTERNAL) {
				Reporter.logLocalPlay(3);
			} else {
				String sAction = intent.getStringExtra("action");
				if (sAction != null) {
					action = PlayerAction.valueOf(sAction);
				}
				playerAdapter.setFromWebView(false);
			}
			videoName = intent.getStringExtra("name");
			switch (openFrom) {
			case NETWORK_PLAY:// 网络播放过来的
				String name = intent.getStringExtra("name");
				playerAdapter.setVideoName(name);

			case LOCAL_INTERNAL:// 本地视频页过来的
				changeOrientation(true, false);
				int index = intent.getIntExtra("index", 0);
				String[] urls = intent.getStringArrayExtra("urls");
				playerAdapter.playUrl(index, urls);
				playerAdapter.setEncryption(false);

				break;
			case ENCRYPTION:// 加密视频页过来的
				changeOrientation(true, false);
				int ind = intent.getIntExtra("index", 0);
				String[] us = intent.getStringArrayExtra("urls");
				playerAdapter.setEncryption(true);
				playerAdapter.playUrl(ind, us);

				break;
			case WEBVIEW:// webview过来的
				changeOrientation(true, false);
				xyzplay = intent.getStringExtra("xyzplay");
				if (action == null) {
					action = PlayerAction.valueOf(intent
							.getStringExtra("action"));
				}
				dfnt = SharedPreferenceModule.getInstance().getString(
						DEFINITION_KEY);
				if (TextUtils.isEmpty(dfnt)) {
					dfnt = "1";
				}
				requestVideoPlayUrl(xyzplay, "1", dfnt, false);

				break;
			case FAST_PLAY_LOCAL:// 播放记录本地视频
			case FAST_PLAY_ONLINE:// 播放记录在线视频
				vgdetail = intent.getStringExtra("vgdetail");
				xyzplay = intent.getStringExtra("xyzplay");
				if (TextUtils.isEmpty(vgdetail)) {
					if (!TextUtils.isEmpty(xyzplay)) {
						if (xyzplay.startsWith("[host]")) {
							// 网络视频
							action = PlayerAction.valueOf(intent
									.getStringExtra("action"));
							dfnt = intent.getStringExtra("dfnt");
							handerUrl();

						} else {
							// 本地视频或者互联网视频
							changeOrientation(true, false);
							urls = new String[] { xyzplay };
							playerAdapter.playUrl(0, urls);
							playerAdapter.setEncryption(false);

						}
					}
				} else {
					// 详情页
					action = PlayerAction.valueOf(intent
							.getStringExtra("action"));
					dfnt = intent.getStringExtra("dfnt");
					handerUrl();
				}
				break;
			case CACHE_LIST:// 来自我的缓存内容列表
				changeOrientation(true, false);
				action = PlayerAction.valueOf(intent.getStringExtra("action"));
				ArrayList<CacheVideo> videos = intent
						.getParcelableArrayListExtra("cachevideos");
				index = intent.getIntExtra("index", 0);
				mTitleSmall.setText(videos.get(index).getName());
				mTitleFull.setText(videos.get(index).getName());
				playerAdapter.playCacheVideo(videos, index);

				break;
			// case NOTIFICATION:// 通知
			// case SEARCH:// 搜索
			// case COLUMN:// 栏目页点击过来的
			// case EVERYONE:// 大家都在看
			// case COLLECTION:// 收藏过来的
			// case LINKVIDEO:// 关联视频过来的
			default:
				vgdetail = intent.getStringExtra("vgdetail");
				xyzplay = intent.getStringExtra("xyzplay");
				action = PlayerAction.valueOf(intent.getStringExtra("action"));
				dfnt = intent.getStringExtra("dfnt");
				handerUrl();
				break;
			}
		}
	}

	/**
	 * 根据action处理url
	 * 
	 * @param url
	 * @return void
	 * @throws
	 */
	private void handerUrl() {
		if (!TextUtils.isEmpty(videoName)) {
			mTitleSmall.setText(videoName);
		}
		if (!FoneUtil.isNetOkWithToast(this)) {
			return;
		}
		switch (action) {
		case DETAIL:// 详情页
			changeOrientation(false, true);
			requestVideoDetail(vgdetail);
			break;
		case FULLPLAY:// 全屏直接播放
			changeOrientation(true, false);
			if (TextUtils.isEmpty(xyzplay)) {
				if (TextUtils.isEmpty(vgdetail)) {
					L.v(TAG, "vgdetail and xyzplay url is null");
					Toast.makeText(FonePlayerActivity.this,
							R.string.video_outline_text, Toast.LENGTH_SHORT)
							.show();
					finish();
					return;
				}
				requestVideoDetail(vgdetail);
				return;
			}
			String defaultDnf = SharedPreferenceModule.getInstance().getString(
					DEFINITION_KEY);
			if (TextUtils.isEmpty(defaultDnf)) {
				defaultDnf = "1";
			}
			requestVideoPlayUrl(xyzplay, "1", defaultDnf, false);
			break;
		}
	}

	/**
	 * 显示airone window
	 * 
	 * @return void
	 * @throws
	 */
	private void showAironeDevicesWindow() {

		if (AirOne.getInstance().getSize() == 1) {
			if (!playerAdapter.isAirOneMode()) {
				playerAdapter.airOneOpen(AirOne.getInstance().getDevice(0));
				AirOne.getInstance().getDevice(0).checked = true;
				return;
			}
		}

		String aircode = null;
		if (playerAdapter.getPlaRst() != null) {
			aircode = playerAdapter.getPlaRst().aircode;
		}

		// 弹出设备窗口
		if (mSelectAireOnePopupWindow == null) {
			mSelectAireOnePopupWindow = new AirOneSelectPopupWindow(
					FonePlayerActivity.this, aircode);// 显示正确的aircode
			AirOne.getInstance().setDeviceChangedListener(
					new AirOne.IDeviceChangedListener() {

						@Override
						public void changed(AirServerDevice dev, boolean add) {
							if (mSelectAireOnePopupWindow != null) {
								((BaseAdapter) mSelectAireOnePopupWindow
										.getListView().getAdapter())
										.notifyDataSetChanged();
							}
						}
					});

			// mSelectAireOnePopupWindow.getPopupWindow().setOnDismissListener(new
			// PopupWindow.OnDismissListener() {
			// @Override
			// public void onDismiss() {
			// }
			// });

			mSelectAireOnePopupWindow.getListView().setOnItemClickListener(
					new OnItemClickListener() {

						@Override
						public void onItemClick(AdapterView<?> parent,
								View view, final int position, long id) {

							AirOneViewHolder holder = (AirOneViewHolder) view
									.getTag();
							holder.selectCheckBox.toggle();

							AirOne.getInstance().getDevice(position).checked = holder.selectCheckBox
									.isChecked();

							if (holder.selectCheckBox.isChecked()) {
								// 投放
								if (!playerAdapter.isAirOneMode()
										&& playerAdapter.isPlaying()) {
									playerAdapter.stop();
									playerAdapter.release();
									videoSurface.setVisibility(View.INVISIBLE);
								}
								playerAdapter.airOneOpen(AirOne.getInstance()
										.getDevice(position));
							} else {
								// 停止投放
								playerAdapter.doAirOneStopDevice(AirOne
										.getInstance().getDevice(position));
							}
						}
					});

		}
		mSelectAireOnePopupWindow.showDeviceInfo();
		// 是否是在线视频
		if (TextUtils.isEmpty(aircode)) {
			mSelectAireOnePopupWindow.show(mBtAirone, false);
		} else {
			mSelectAireOnePopupWindow.setAricode(aircode);
			mSelectAireOnePopupWindow.show(mBtAirone, true);
		}
	}

	/**
	 * 请求剧集
	 * 
	 * @param url
	 *            地址
	 * @return void
	 * @throws
	 */
	private void requestSeriesRst(String url) {
		L.v(TAG, "全屏请求剧集--- ");
		Request.getInstance().drama(FoneUtil.handleUrl(url),
				new com.fone.player.client.Callback<DramaRst>() {

					@Override
					public void onSuccess(DramaRst t) {
						if (t != null && playerAdapter != null && t.result == 0) {// 剧集请求成功
							// 如果dramaRst是空的，那么就填充
							if (seriesRst == null
									|| !seriesRst.name.equals(t.name)) {
								seriesRst = t;

								updateSeriesView();
								if (seriesRst.cntsList != null
										&& seriesRst.cntsList.get(0).showtyp != 0) {
									// 不规则显示
									// updateSeriesView();
									if (seriesRst.cntsList.size() > t.rp.p) {
										requestSeriesRst(seriesRst.cntsList
												.get(t.rp.p).url);
									}
								}
							} else {
								// 填充到seriesRst的对应cntsList上
								if (seriesRst.cntsList.get(t.rp.p - 1).cntList == null) {
									seriesRst.cntsList.get(t.rp.p - 1).cntList = t.cntsList
											.get(t.rp.p - 1).cntList;
								}
								if (seriesRst.cntsList != null
										&& seriesRst.cntsList.get(0).showtyp == 0) {// 规则显示
									if (ruleSeriesPagerSelectedIndex == t.rp.p - 1) {
										ruleSeriesItemAdapter.setData(seriesRst.cntsList
												.get(t.rp.p - 1).cntList);
									}
								} else {// 不规则显示
									updateSeriesView();
									if (seriesRst.cntsList.size() > t.rp.p) {
										requestSeriesRst(seriesRst.cntsList
												.get(t.rp.p).url);
									}
								}
							}

						} else {
							if (t == null) {
								Toast.makeText(mContext,
										R.string.player_network_not_stable,
										Toast.LENGTH_SHORT).show();
							} else {
								if (t != null && t.error != null
										&& t.error.errormsg != null) {
									L.v(TAG, "requestSeriesRst error "
											+ t.error.errormsg);
									Toast.makeText(mContext, t.error.errormsg,
											Toast.LENGTH_SHORT).show();
								}
							}
						}
					}

					@Override
					public void onFailure(Error error) {
						if (!error.isNetworkError()) {
							if (error.getStatus() == 404) {
								// 未找到
								Toast.makeText(mContext,
										R.string.video_outline_text,
										Toast.LENGTH_SHORT).show();
							} else {
								L.v(TAG,
										"requestSeriesRst onFailure "
												+ error.getReason());
								// Toast.makeText(mContext, error.getReason(),
								// Toast.LENGTH_SHORT).show();
							}
						}
					}
				});
	}

	/**
	 * 规则剧集选中的Tab index
	 */
	private int ruleSeriesPagerSelectedIndex = 0;

	/**
	 * 更新剧集layout
	 * 
	 * @return void
	 * @throws
	 */
	private void updateSeriesView() {
		// 更新view,包括剧集分页
		if (seriesRst.cntsList.get(0).showtyp == 0) {// 规则剧集
			ruleSeriesPagerSelectedIndex = 0;
			seriesRst.cntsList.get(0).isChecked = true;
			if (ruleSeriesPagerAdapter == null) {
				ruleSeriesPagerAdapter = new GridSeriesTabItemAdapter(
						seriesRst.cntsList, true);
				ruleSeriesPagerGrid.setAdapter(ruleSeriesPagerAdapter);
			} else {
				ruleSeriesPagerAdapter.setData(seriesRst.cntsList);
			}
			ruleSeriesPagerGrid.setOnScrollListener(fullLinkScrollListener);
			ruleSeriesItemAdapter = new FullRuleSeriesItemAdapter(
					seriesRst.cntsList.get(0).cntList,
					playerAdapter.getXyzPlayUrl());
			ruleSeriesItemGrid.setAdapter(ruleSeriesItemAdapter);
			ruleSeriesItemGrid.setOnScrollListener(fullLinkScrollListener);
			ruleSeriesPagerGrid
					.setOnItemClickListener(new AdapterView.OnItemClickListener() {
						@Override
						public void onItemClick(AdapterView<?> parent,
								View view, int position, long id) {
							ruleSeriesPagerSelectedIndex = position;
							DramaRst.Cnts cnts = seriesRst.cntsList
									.get(position);
							if (!cnts.isChecked) {
								for (DramaRst.Cnts cs : seriesRst.cntsList) {
									cs.isChecked = false;
								}
								cnts.isChecked = true;
								ruleSeriesPagerAdapter.notifyDataSetChanged();
								if (cnts.cntList == null
										|| cnts.cntList.size() == 0) {
									ruleSeriesItemAdapter.setData(null);
									requestSeriesRst(cnts.url);
								} else {
									ruleSeriesItemAdapter.setData(cnts.cntList);
								}
							}
						}
					});
			ruleSeriesItemGrid
					.setOnItemClickListener(new AdapterView.OnItemClickListener() {
						@Override
						public void onItemClick(AdapterView<?> arg0, View arg1,
								int arg2, long arg3) {
							if (isBuffering()) {
								return;
							}
							if (FoneUtil
									.isNetOkWithToast(FonePlayerActivity.this)) {
								DramaRst.Cnt cnt = (Cnt) ruleSeriesItemAdapter
										.getItem(arg2);
								if (!FoneUtil.getCIdByUrl(cnt.url).equals(
										ruleSeriesItemAdapter.getcId())) {
									VideoPlayerMessage msg = new VideoPlayerMessage();
									msg.what = VideoPlayerMessage.MESSGAE_CHANGE_VIDEO;
									msg.obj = new ChangeVideoEvent(cnt.url,
											false, true, false);
									EventBus.getDefault().post(msg);
									hideFullRightLayout();
								}
							}
						}
					});
			refreshTabView();
			fullRuleSeriesPagerHorizontalSV
					.setOnScrollListener(fullRuletabScrollListener);
		} else {
			// 非规则剧集
			List<DramaRst.Cnt> dramas = new ArrayList<DramaRst.Cnt>();
			for (DramaRst.Cnts cnts : seriesRst.cntsList) {
				if (cnts != null && cnts.cntList != null
						&& cnts.cntList.size() > 0) {
					dramas.addAll(cnts.cntList);
				}
			}
			if (unRuleSeriesItemAdapter == null) {
				unRuleSeriesItemAdapter = new UnRuleSeriesItemAdapter(dramas,
						playerAdapter.getXyzPlayUrl());
				fullPlayerLinkList.setAdapter(unRuleSeriesItemAdapter);
				fullPlayerLinkList.setOnScrollListener(fullLinkScrollListener);
				fullPlayerLinkList
						.setOnItemClickListener(fullUnRuleItemClickListener);
			} else {
				unRuleSeriesItemAdapter.setData(dramas);
			}
		}
	}

	private EnhanceHorizontalScrollView.OnScrollListener fullRuletabScrollListener = new EnhanceHorizontalScrollView.OnScrollListener() {

		@Override
		public void onScrollStateChanged(HorizontalScrollView view,
				int scrollState) {
			L.v(TAG, "fullRuletabScrollListener onScrollStateChanged");
			// 延迟layout隐藏时间
			if (scrollState == EnhanceHorizontalScrollView.OnScrollListener.SCROLL_STATE_START) {
				mHandler.removeCallbacks(hideFullScreenLayoutRunnable);
			} else {
				mHandler.postDelayed(hideFullScreenLayoutRunnable,
						controlAutoHideTime);
			}
		}

		@Override
		public void onScroll(int scrollX) {
		}
	};

	private AdapterView.OnItemClickListener fullUnRuleItemClickListener = new AdapterView.OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			if (isBuffering()) {
				return;
			}
			DramaRst.Cnt cnt = (Cnt) unRuleSeriesItemAdapter.getItem(arg2);
			if (FoneUtil.isNetOkWithToast(FonePlayerActivity.this)
					&& !FoneUtil.getCIdByUrl(cnt.url).equals(
							unRuleSeriesItemAdapter.getCid())) {
				VideoPlayerMessage msg = new VideoPlayerMessage();
				msg.what = VideoPlayerMessage.MESSGAE_CHANGE_VIDEO;
				msg.obj = new ChangeVideoEvent(cnt.url, false, true, false);
				EventBus.getDefault().post(msg);
				hideFullRightLayout();
			}
		}
	};

	/**
	 * 全屏相关视频/剧集滑动时不隐藏控制layout
	 */
	private AbsListView.OnScrollListener fullLinkScrollListener = new AbsListView.OnScrollListener() {

		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState) {
			L.v(TAG, "fullLinkScrollListener onScrollStateChanged");
			// 延迟layout隐藏时间
			if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING
					|| scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
				mHandler.removeCallbacks(hideFullScreenLayoutRunnable);
			} else {
				mHandler.postDelayed(hideFullScreenLayoutRunnable,
						controlAutoHideTime);
			}
		}

		@Override
		public void onScroll(AbsListView view, int firstVisibleItem,
				int visibleItemCount, int totalItemCount) {
		}
	};

	/**
	 * 初始化手势监听
	 */
	private void initPlayerGestureListener() {

		L.v(TAG, "initPlayerGestureListener", "start");
		FoneOnGesture foneOnGesture = new FoneOnGesture();
		foneOnGesture
				.setFoneOnGestureListener(new FoneOnGesture.FoneOnGestureListener() {

					@Override
					public void FoneOnGestureStart() {
						if (getGestureIsEnable()) {
							L.v(TAG, "initPlayerGestureListener",
									"FoneOnGestureStart");
							mHandler.removeCallbacks(hideFullScreenLayoutRunnable);
						}
					}

					int width;
					int airOneVolAdd = 0;

					@Override
					public void FoneOnGestureMoveUPOrDown(boolean isEnableSeek,
							float distance, float start_x, boolean two_pointer) {
						if (getGestureIsEnable() && !lock) {
							L.v(TAG, "initPlayerGestureListener",
									"FoneOnGestureMoveUPOrDown");
							L.v(TAG, "initPlayerGestureListener",
									"isEnableSeek=" + isEnableSeek
											+ "  distance=" + distance
											+ "  start_x=" + start_x
											+ "  two_pointer=" + two_pointer);
							if (width == 0) {
								width = ScreenUtil
										.getScreenWidthPix(FonePlayerActivity.this);
							}
							gestureChangeVolOrBright = true;
							// 修改音量/亮度
							int status = (width / 2 < start_x) ? 2 : 1;
							if (status == 1) {
								// 修改音量
								int addVol = (int) (distance / (ScreenUtil
										.getScreenHeightPix(FonePlayerActivity.this) / 50));
								volPercentage -= addVol;
								if (playerAdapter.isAirOneMode()) {
									airOneVolAdd += addVol;
								} else {
									currentVolume = (int) (((double) volPercentage / 100) * maxVolume);
									if (volPercentage >= 100) {
										volPercentage = 100;
										currentVolume = maxVolume;
									}
									if (volPercentage <= 0) {
										volPercentage = 0;
										currentVolume = 0;
									}
									updateVolume();
								}
							} else {
								// 修改亮度
								float addBright = distance
										/ (float) (ScreenUtil
												.getScreenHeightPix(FonePlayerActivity.this) * 10);
								currentBrightness -= addBright;
								if (currentBrightness >= 1) {
									currentBrightness = 1;
								}
								if (currentBrightness <= 0) {
									currentBrightness = 0;
								}
								updateBright();
							}

						}
					}

					@Override
					public void FoneOnGestureMovePrevious() {
						if (getGestureIsEnable()) {
							L.v(TAG, "initPlayerGestureListener",
									"FoneOnGestureMovePrevious");
							// onPlayerPreviousAction();
						}
					}

					@Override
					public void FoneOnGestureMoveNext() {
						if (getGestureIsEnable()) {
							L.v(TAG, "initPlayerGestureListener",
									"FoneOnGestureMoveNext");
							// onPlayerNextAction();
						}
					}

					int currentProgress;

					@Override
					public void FoneOnGestureMoveLeftOrRight(
							boolean isEnableSeek, float eventY, float distance) {
						if (getGestureIsEnable() && !lock) {
							L.v(TAG, "initPlayerGestureListener",
									"FoneOnGestureMoveLeftOrRight");
							try {
								if (!playerAdapter.isLiveVideo()) {
									int videoDruation = playerAdapter
											.getMediaDuration();
									if (videoDruation > 0) {
										// 调节进度
										gestureChangeProgress = true;
										currentProgress = playerAdapter
												.getCurrentPosition();
										// 每滑动10像素加1秒
										currentProgress -= distance / 10 * 1000;
										if (currentProgress <= 0) {
											currentProgress = 0;
										}
										if (currentProgress >= playerAdapter
												.getMediaDuration()) {
											currentProgress = playerAdapter
													.getMediaDuration();
										}
										gestureUpdateProgress(currentProgress);
									}
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					}

					long lastClickTime;

					@Override
					public void FoneOnGestureEnd(boolean isEnableSeek,
							boolean isLeftOrRight) {
						L.v(TAG, "initPlayerGestureListener",
								"FoneOnGestureEnd isEnableSeek: "
										+ isEnableSeek + " ,isLeftOrRight:"
										+ isLeftOrRight);
						if (!gestureChangeVolOrBright
								&& !gestureChangeProgress
								&& playerAdapter != null
								&& !playerAdapter.isAirOneMode()
								&& !lock
								&& System.currentTimeMillis() - lastClickTime < 300) {
							// 双击
							mHandler.removeCallbacks(gestureEndRun);
							lastClickTime = 0;
							if (playerAdapter != null) {
								playerAdapter.doChangeFrameScale();
								switch (playerAdapter.getFrameScale()) {
								case 0:// 等比例
									Toast.makeText(FonePlayerActivity.this,
											R.string.fullplayer_scale_tips1,
											Toast.LENGTH_SHORT).show();
									break;
								case 1:// 全屏拉伸
									Toast.makeText(FonePlayerActivity.this,
											R.string.fullplayer_scale_tips2,
											Toast.LENGTH_SHORT).show();
									break;
								case 2:// 原始大小
									Toast.makeText(FonePlayerActivity.this,
											R.string.fullplayer_scale_tips0,
											Toast.LENGTH_SHORT).show();
									break;

								default:
									break;
								}
							}
						} else {
							if (lock
									&& mFullLeft.getVisibility() != View.VISIBLE) {
								Toast.makeText(FonePlayerActivity.this,
										R.string.unlock_text,
										Toast.LENGTH_SHORT).show();
							}
							// 单击
							mHandler.postDelayed(gestureEndRun, 300);
							lastClickTime = System.currentTimeMillis();
						}
					}

					/**
					 * 单击时运行
					 */
					Runnable gestureEndRun = new Runnable() {
						@Override
						public void run() {
							if (gestureChangeVolOrBright
									|| gestureChangeProgress) {
								if (gestureChangeProgress) {
									playerAdapter.seekTo(currentProgress);
									playerAdapter
											.setCurrentPostion(currentProgress);
									showProgressDialog(
											getString(R.string.video_loading_message),
											false);
								}
								if (airOneVolAdd != 0) {
									playerAdapter
											.airOneAddVolme(0 - airOneVolAdd / 10);
									airOneVolAdd = 0;
								}
								gestureChangeVolOrBright = false;
								gestureChangeProgress = false;
								mHandler.postDelayed(
										hideGenstureLayoutRunnable, 3000);
								mHandler.postDelayed(
										hideFullScreenLayoutRunnable,
										controlAutoHideTime);
							} else if (mFullLeft.getVisibility() == View.VISIBLE) {
								hideFullScreenLayout();
							} else {
								showFullScreenLayout();
								mHandler.postDelayed(
										hideFullScreenLayoutRunnable,
										controlAutoHideTime);
							}
						}
					};

					@Override
					public void FoneOnGesture() {
					}
				});

		mPlayerGestureView.addOnGestureListener(foneOnGesture);

	}

	/**
	 * 显示全屏layout
	 * 
	 * @return void
	 * @throws
	 */
	private void showFullScreenLayout() {
		if (!lock) {
			mFullTitleBar.setVisibility(View.VISIBLE);
			mFullContorlBar.setVisibility(View.VISIBLE);
			mFullRight.setVisibility(View.VISIBLE);
			if (playerAdapter != null && playerAdapter.isAirOneMode()) {
				mFullLeft.setVisibility(View.INVISIBLE);
			} else {
				mFullLeft.setVisibility(View.VISIBLE);
			}
		} else {
			mFullLeft.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 显示airone正在播放layout
	 * 
	 * @return void
	 * @throws
	 */
	private void showAirOnePlayingLayout() {
		airOnePlayingLayout.setVisibility(View.VISIBLE);
	}

	/**
	 * 隐藏airone正在播放layout
	 * 
	 * @return void
	 * @throws
	 */
	private void hideAirOnePlayingLayout() {
		airOnePlayingLayout.setVisibility(View.GONE);
		if (mSelectAireOnePopupWindow != null
				&& mSelectAireOnePopupWindow.isShowing()) {
			mSelectAireOnePopupWindow.dismiss();
		}
	}

	/**
	 * 延迟3秒隐藏全屏layout
	 * 
	 * @return void
	 * @throws
	 */
	private void sendHidePlayerControlLayoutHander() {
		if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
			mHandler.removeCallbacks(hideFullScreenLayoutRunnable);
			mHandler.postDelayed(hideFullScreenLayoutRunnable,
					controlAutoHideTime);
		} else {
			mHandler.removeCallbacks(hideSmallControlViewRun);
			mHandler.postDelayed(hideSmallControlViewRun, controlAutoHideTime);
		}
	}

	/**
	 * 隐藏全屏layout
	 * 
	 * @return void
	 * @throws
	 */
	private void hideFullScreenLayout() {
		if (playerAdapter != null && !playerAdapter.isAirOneMode()) {
			mFullTitleBar.setVisibility(View.INVISIBLE);
			mFullLeft.setVisibility(View.INVISIBLE);
			mFullContorlBar.setVisibility(View.INVISIBLE);
			mFullRight.setVisibility(View.INVISIBLE);
			mFullRightSeriesRecommend.setVisibility(View.GONE);
			mFullRecommend.setTextColor(getResources().getColor(
					R.color.video_full_recommend_series_textcolor));
			mFullSeries.setTextColor(getResources().getColor(
					R.color.video_full_recommend_series_textcolor));
		}
		hideSecondMenu();
		moreMenuLayout.setVisibility(View.INVISIBLE);
		fullMore.setBackgroundResource(R.drawable.detail_icon_play_more);
		if (definitionPopupWindow != null) {
			definitionPopupWindow.dismiss();
		}
	}

	/**
	 * 更新进度
	 * 
	 * @param currentProgress
	 * @return void
	 * @throws
	 */
	protected void gestureUpdateProgress(int currentProgress) {
		L.v(TAG, "gestureUpdateProgress");
		mHandler.removeCallbacks(hideGenstureLayoutRunnable);
		tvGestureProgress.setText("");
		genstureLayout.setVisibility(View.VISIBLE);
		soundBrightLayout.setVisibility(View.GONE);
		ivSoundBright.setVisibility(View.GONE);
		tvGestureProgress.setVisibility(View.VISIBLE);
		String curStr = FoneUtil.second2MinuteStr(currentProgress / 1000);
		String durStr = FoneUtil.second2MinuteStr(playerAdapter
				.getMediaDuration() / 1000);
		SpannableString ss = new SpannableString(curStr);
		ss.setSpan(
				new ForegroundColorSpan(getResources().getColor(
						R.color.video_info_tab_line)), 0, curStr.length(),
				Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		tvGestureProgress.append(ss);
		ss = new SpannableString("/" + durStr);
		ss.setSpan(new ForegroundColorSpan(Color.WHITE), 0,
				durStr.length() + 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		tvGestureProgress.append(ss);
		mSeekBar.setProgress(currentProgress);
		mSeekBar_full.setProgress(currentProgress);
		tvFullProgress.setText(FoneUtil.second2MinuteStr(Math
				.round((float) currentProgress / 1000f)));
		tvSmallProgress.setText(FoneUtil.second2MinuteStr(Math
				.round((float) currentProgress / 1000f)));
	}

	/**
	 * 更新亮度
	 * 
	 * @return void
	 * @throws
	 */
	private void updateBright() {
		mHandler.removeCallbacks(hideGenstureLayoutRunnable);
		genstureLayout.setVisibility(View.VISIBLE);
		soundBrightLayout.setVisibility(View.VISIBLE);
		ivSoundBright.setVisibility(View.VISIBLE);
		tvSoundBright.setVisibility(View.VISIBLE);
		tvGestureProgress.setVisibility(View.GONE);
		ivSoundBright.setImageResource(R.drawable.full_icon_gesture_bright);

		WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.screenBrightness = currentBrightness;
		getWindow().setAttributes(lp);

		tvSoundBright.setText((int) (currentBrightness * 100) + "%");
	}

	/**
	 * 更新音量
	 * 
	 * @return void
	 * @throws
	 */
	private void updateVolume() {
		mHandler.removeCallbacks(hideGenstureLayoutRunnable);
		genstureLayout.setVisibility(View.VISIBLE);
		soundBrightLayout.setVisibility(View.VISIBLE);
		ivSoundBright.setVisibility(View.VISIBLE);
		tvSoundBright.setVisibility(View.VISIBLE);
		tvGestureProgress.setVisibility(View.GONE);

		audiomanage
				.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0);
		if (volPercentage == 0) {
			ivSoundBright
					.setImageResource(R.drawable.full_icon_gesture_sound_un);
		} else {
			ivSoundBright.setImageResource(R.drawable.full_icon_gesture_sound);
		}
		tvSoundBright.setText(volPercentage + "%");
	}

	/**
	 * 隐藏 音量/亮度/进度显示区
	 */
	private Runnable hideGenstureLayoutRunnable = new Runnable() {

		@Override
		public void run() {
			genstureLayout.setVisibility(View.GONE);
		}
	};

	/**
	 * 隐藏 音量/亮度/进度显示区
	 */
	private Runnable hideFullScreenLayoutRunnable = new Runnable() {

		@Override
		public void run() {
			hideFullScreenLayout();
		}
	};

	/**
	 * 获取是否支持手势
	 * 
	 * @return true支持收拾,false不支持
	 */
	public boolean getGestureIsEnable() {
		return true;
	}

	/**
	 * 点击返回按键的时间，判断双击时使用
	 */
	private long backClickTiem = 0;

	@Override
	public void onBackPressed() {

		L.v(TAG, "onBackPressed");

		if (playerAdapter != null && !playerAdapter.isOpenSuccess()) {
			return;
		}

		if (isAddingCache) {
			return;
		}

		if (!lock) {

			if (System.currentTimeMillis() - backClickTiem < 1000) {
				backClickTiem = System.currentTimeMillis();
				// 双击
				return;
			} else {
				backClickTiem = System.currentTimeMillis();
			}

			if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
				if (playerAdapter.isAirOneMode()) {
					playerAdapter.stop();
				} else {
					if (openFrom == THIRDPARTY) {// 第三方来的
						if (playerAdapter != null) {
							playerAdapter.stop();
							playerAdapter.release();
						}

						Reporter.logPlayerClose();

						ApplicationManage.getAplicationManageInstance()
								.exitSystem();
						return;
					}
					if (playerAdapter.getVideoMode() == VideoMode.LOCAL
							|| playerAdapter.getVideoMode() == VideoMode.NETWORK) {
						finish();
						return;
					} else {
						if (action == PlayerAction.FULLPLAY) {
							finish();
							return;
						} else {
							changeOrientation(false, false);
							fromWebViewHandler();
						}
					}
				}
			} else {
				finish();
			}
		}

	}

	private void fromWebViewHandler() {
		if (openFrom == WEBVIEW) {
			// 原网页过来的要停止播放，显示h5
			// bug 2321
			playerAdapter.stop();
			playerAdapter.release();
			playerAdapter = null;
			initPlayerAdapter();
			playerAdapter.setVideoDetail(videoDetail, currentFromIndex);
			showH5background();
			dismessProgressDialog();
		}
	}

	/**
	 * 获取屏幕方向
	 * 
	 * @return
	 * @return int
	 * @throws
	 */
	private int getScreenOrientation() {
		return this.getResources().getConfiguration().orientation;
	}

	/**
	 * 请求视频详情
	 * 
	 * @param context
	 * @param url
	 * @return void
	 * @throws
	 */
	private void requestVideoDetail(String url) {
		requestVideoInfo = true;
		vgdetail = url;
		showLoadingDialog();
		// showProgressDialog(getString(R.string.video_loading_message), false);
		Request.getInstance().vgdetail(FoneUtil.handleUrl(vgdetail),
				new RequestCallBack());
	}

	/**
	 * 请求播放地址Xyzplay
	 * 
	 * @param context
	 * @param url
	 * @param pt
	 *            播放类型信息 pt=1—播放 pt=2—下载 pt=3—下载成功上报
	 * @param fnt
	 *            清晰度类型：1标清\2高清\3超清
	 * @param isChangeSeries
	 *            是否是切换剧集
	 * @return void
	 * @throws
	 */
	private void requestVideoPlayUrl(String url, String pt, String fnt,
			final boolean isChangeSeries) {
		// 设置当前播放的xyzPlayUrl
		showLoadingDialog();
		// showProgressDialog(getString(R.string.video_loading_message), false);
		if (!TextUtils.isEmpty(fnt)) {
			url = url + "&dfnt=" + fnt;
		}
		playerAdapter.setXyzPlayUrl(url);
		requestVideoPlayUrl(url, pt, isChangeSeries);
	}

	/**
	 * 请求播放地址Xyzplay
	 * 
	 * @param context
	 * @param url
	 * @param pt
	 *            播放类型信息 pt=1—播放 pt=2—下载 pt=3—下载成功上报
	 * @param fnt
	 *            清晰度类型：1标清\2高清\3超清
	 * @param isChangeSeries
	 *            是否是切换剧集
	 * @return void
	 * @throws
	 */
	private void requestVideoPlayUrl(final String url, String pt,
			final boolean isChangeSeries) {
		requestVideoInfo = true;
		// 设置当前播放的xyzPlayUrl
		showLoadingDialog();
		// showProgressDialog(getString(R.string.video_loading_message), false);
		playerAdapter.setXyzPlayUrl(url);
		String comefrom = "";
		if (openFrom < 20) {
			switch (openFrom) {
			case SEARCH_ENTRANCE:
				comefrom = SEARCH_NORMAL + "";
				break;
			case FAST_PLAY_LOCAL:
				comefrom = FAST_PLAY_ONLINE + "";
				break;
			default:
				break;
			}
		} else {
			comefrom = openFrom + "";
		}

		Request.getInstance().xyzplay(FoneUtil.handleUrl(url), pt, comefrom,
				new com.fone.player.client.Callback<XyzplaRst>() {

					@Override
					public void onSuccess(XyzplaRst t) {
						dismessLoadingDialog();
						requestVideoInfo = false;
						if (playerAdapter == null || stop) {
							L.v(TAG,
									"playerAdapter == null || stop XyzplaRst callback return!");
							return;
						}
						// 请求成功
						if (t != null && t.result == 0) {
							// 设置播放地址
							if (playerAdapter == null) {
								return;
							}
							if (t.cnt.fraglist == null
									|| t.cnt.fraglist.fragList == null
									|| t.cnt.fraglist.fragList.size() == 0) {
								dismessLoadingDialog();
								Reporter.logError(
										FoneUtil.getCIdByUrl(url) == null ? ""
												: FoneUtil.getCIdByUrl(url),
										Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
								// 没有获取到播放地址
								Toast.makeText(FonePlayerActivity.this,
										R.string.video_outline_text,
										Toast.LENGTH_SHORT).show();
								return;
							}
							playerAdapter.setPlayerRst(t, action);
							if (isChangeSeries
									&& action == PlayerAction.DETAIL
									&& playerAdapter.getCurrentFrom() != null
									&& playerAdapter.getCurrentFrom().toply == 1) {
								// 切换剧集来的,如果是第三方播放器的就进行播放
								go3rdPlayer();
							}
							mTitleSmall.setText(t.cnt.name);
							if (t.cnt.ftv == 0
									&& !TextUtils.isEmpty(t.cnt.ourl)) {// 不收费
								mTitleFull.setText(t.cnt.name + "（"
										+ t.cnt.ourl + "）");
								// 是否有剧集
								if (!TextUtils.isEmpty(t.nexturl)
										|| !TextUtils.isEmpty(t.provurl)) {// 有下一集url说明有剧集
									if (t.dramaurl != null) {
										if (!isChangeSeries) {
											seriesRst = null;
											requestSeriesRst(t.dramaurl);
										}
										mFullSeries.setVisibility(View.VISIBLE);
									} else {
										mFullSeries.setVisibility(View.GONE);
									}
								} else {
									mFullSeries.setVisibility(View.GONE);
								}

							} else {// 收费
								mTitleFull.setText(t.cnt.name);
								mFullSeries.setVisibility(View.GONE);
							}
							if (t.cnt.dfnts != null
									&& t.cnt.dfnts.dfntList != null
									&& !playerAdapter.isLiveVideo()) {
								// 显示清晰度
								for (XyzplaRst.Dfnt dfnt : t.cnt.dfnts.dfntList) {
									if (dfnt.cur == 1) {// 表示是当前播放的视频清晰度
										updateDefinition(dfnt.t);
									}
								}
							} else {
								mFullDefinition.setVisibility(View.GONE);
							}
							// 请求相关视频
							requestFullLinkVideo();
						} else {
							dismessLoadingDialog();
							Reporter.logError(
									FoneUtil.getCIdByUrl(url) == null ? ""
											: FoneUtil.getCIdByUrl(url),
									Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
							if (t == null) {
								Toast.makeText(mContext,
										R.string.player_network_not_stable,
										Toast.LENGTH_SHORT).show();
							} else if (t.error != null) {
								L.v(TAG, "requestVideoPlayUrl error "
										+ t.error.errormsg);
								// 切换来源
								if (playerAdapter != null
										&& playerAdapter.getVideoDetail() != null) {
									if (playerAdapter.getVideoDetail().froms.fromList
											.size() > currentFromIndex + 1) {
										// 切换来源:找到下一个来源
										currentFromIndex++;
										if (fromWindow != null) {
											fromWindow
													.setCurrentFrom(playerAdapter
															.getVideoDetail().froms.fromList
															.get(currentFromIndex));
										}
										playerAdapter.setCurrentFrom(playerAdapter
												.getVideoDetail().froms.fromList
												.get(currentFromIndex));
										return;
									}
								}
								Toast.makeText(mContext,
										R.string.video_outline_text,
										Toast.LENGTH_SHORT).show();
							}
						}
					}

					@Override
					public void onFailure(Error error) {
						requestVideoInfo = false;
						Reporter.logError(
								FoneUtil.getCIdByUrl(url) == null ? ""
										: FoneUtil.getCIdByUrl(url),
								Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
						// 请求播放地址失败
						dismessLoadingDialog();
						if (error.isNetworkError()) {
							Toast.makeText(mContext,
									R.string.player_network_not_stable,
									Toast.LENGTH_SHORT).show();
						} else {
							// 未找到
							L.v(TAG,
									"requestVideoPlayUrl onFailure "
											+ error.getReason());
							Toast.makeText(mContext,
									R.string.video_outline_text,
									Toast.LENGTH_SHORT).show();
							// Toast.makeText(mContext, error.getReason(),
							// Toast.LENGTH_SHORT).show();
						}
					}
				});
	}

	/**
	 * 更新清晰度背景
	 * 
	 * @param dfnt
	 * @return void
	 * @throws
	 */
	private void updateDefinition(int dfnt) {
		mFullDefinition.setVisibility(View.VISIBLE);
		switch (dfnt) {
		case 1:// 标清
			mFullDefinition
					.setBackgroundResource(R.drawable.full_icon_play_control_standard);
			break;
		case 2:// 高清
			mFullDefinition
					.setBackgroundResource(R.drawable.full_icon_play_control_high);
			break;
		case 3:// 超清
			mFullDefinition
					.setBackgroundResource(R.drawable.full_icon_play_control_supper);
			break;
		default:
			break;
		}
	}

	/**
	 * 请求视频详情回调
	 * 
	 * @author kongxiaojun
	 * @since 2014-5-20
	 */
	private class RequestCallBack implements
			com.fone.player.client.Callback<VgdetailRst> {

		public RequestCallBack() {
			super();
		}

		@Override
		public void onSuccess(VgdetailRst t) {
			requestVideoInfo = false;
			// 发送到播放
			if (playerAdapter == null || stop) {
				L.v(TAG,
						"playerAdapter == null || stop VgdetailRst callback return");
				return;
			}
			if (t != null && t.result == 0) {
				videoDetail = t;
				if (t.froms.fromList == null || t.froms.fromList.size() == 0) {
					dismessLoadingDialog();
					Reporter.logError(
							FoneUtil.getCIdByUrl(vgdetail) == null ? ""
									: FoneUtil.getCIdByUrl(vgdetail),
							Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
					Toast.makeText(mContext, R.string.video_outline_text,
							Toast.LENGTH_SHORT).show();
					return;
				} else {
					if (playerAdapter != null) {
						currentFromIndex = 0;
						playerAdapter.setVideoDetail(t, currentFromIndex);
						playerAdapter.setShost(t.shost);
					}
				}

				if (!UserInfoManager.isLogin()) {
					long videoId = 0;
					try {
						videoId = Integer.valueOf(FoneUtil
								.getVideoIdByUrl(t.furl.url));
					} catch (NumberFormatException e) {
						e.printStackTrace();
					}
					if (StorageModule.getInstance().isFavourite(videoId)) {
						playerAdapter.getVideoDetail().fstate = 1;

					} else {
						playerAdapter.getVideoDetail().fstate = 0;
					}
				}
			} else {
				dismessLoadingDialog();
				if (t == null) {
					Toast.makeText(mContext,
							R.string.player_network_not_stable,
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(mContext, R.string.video_outline_text,
							Toast.LENGTH_SHORT).show();
				}
				Reporter.logError(FoneUtil.getCIdByUrl(vgdetail) == null ? ""
						: FoneUtil.getCIdByUrl(vgdetail),
						Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
				finish();
			}
		}

		@Override
		public void onFailure(Error error) {
			requestVideoInfo = false;
			Reporter.logError(FoneUtil.getCIdByUrl(vgdetail) == null ? ""
					: FoneUtil.getCIdByUrl(vgdetail),
					Reporter.ErrorType.ONLLINE_PLAY_ERROR);// 在线播放失败
			// 提示
			dismessLoadingDialog();
			if (error.isNetworkError()) {
				Toast.makeText(mContext, R.string.player_network_not_stable,
						Toast.LENGTH_SHORT).show();
			} else {
				// 未找到
				L.v(TAG, "RequestCallBack onFailure " + error.getReason());
				Toast.makeText(mContext, R.string.video_outline_text,
						Toast.LENGTH_SHORT).show();
				// Toast.makeText(mContext, error.getReason(),
				// Toast.LENGTH_SHORT).show();
			}
		}

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_VOLUME_UP:// 音量加
			currentVolume++;
			if (currentVolume > maxVolume) {
				currentVolume = maxVolume;
			}
			if (currentVolume < 0) {
				currentVolume = 0;
			}
			volPercentage = (int) ((double) currentVolume / (double) maxVolume * 100);
			tvSoundBright.setText(volPercentage + "%");
			break;
		case KeyEvent.KEYCODE_VOLUME_DOWN:// 音量减
			currentVolume--;
			if (currentVolume > maxVolume) {
				currentVolume = maxVolume;
			}
			if (currentVolume < 0) {
				currentVolume = 0;
			}
			volPercentage = (int) ((double) currentVolume / (double) maxVolume * 100);
			tvSoundBright.setText(volPercentage + "%");
			break;
		default:
			break;
		}
		return super.onKeyDown(keyCode, event);
	}

	/**
	 * 视频是否下线，如果下线会有相关提示
	 * 
	 * @return true 下线 false 没有下线
	 */
	private boolean isVideoOutLineWithToast() {
		// 是否已经下线
		if (isVideoOutLine()) {
			Toast.makeText(FonePlayerActivity.this,
					R.string.video_outline_text, Toast.LENGTH_SHORT).show();
			return true;
		}
		return false;
	}

	/**
	 * 视频是否下线
	 * 
	 * @return true 下线 false 没有下线
	 */
	private boolean isVideoOutLine() {
		// 是否已经下线
		if (playerAdapter.getVideoDetail() != null
				&& playerAdapter.getCurrentFrom() != null
				&& playerAdapter.getCurrentFrom().toply == 1) {
			return false;
		}
		if (openFrom != WEBVIEW && action == PlayerAction.DETAIL) {
			if (playerAdapter.getVideoDetail() == null
					|| playerAdapter.getVideoDetail().froms == null
					|| playerAdapter.getVideoDetail().froms.fromList == null
					|| playerAdapter.getVideoDetail().froms.fromList.size() == 0
					|| playerAdapter.getCurrentFrom() == null
					|| TextUtils
							.isEmpty(playerAdapter.getCurrentFrom().defaulturl)
					|| playerAdapter.getPlaRst() == null) {
				// 视频已经下线
				return true;
			}
		} else {
			if (playerAdapter.getPlaRst() == null) {
				// 视频已经下线
				return true;
			}
		}
		return false;
	}

	/**
	 * 更新来源view
	 * 
	 * @return void
	 * @throws
	 */
	private void updateFromImage(From from) {
		if (TextUtils.isEmpty(from.logo)) {
			fromIcon.setImageResource(R.drawable.source_knowun);
		} else {
			ImageLoader.getInstance().displayImage(from.logo, fromIcon,
					fromOptions);
		}
	}

	/**
	 * 设置SurfaceView的宽高
	 * 
	 * @param width
	 * @param height
	 * @return void
	 * @throws
	 */
	private void setSurfaceWidthHeight(int width, int height) {
		// 设置SurfaceView的宽高
		RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
				width, height);
		int leftRight = (ScreenUtil.getScreenWidthPix(FonePlayerActivity.this) - width) / 2;
		int topBottom = 0;
		if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
			topBottom = (ScreenUtil.getScreenHeightPix(FonePlayerActivity.this) - height) / 2;
			if (topBottom <= 0) {
				topBottom = 1;
			}
		}
		params.setMargins(leftRight, topBottom, leftRight, topBottom);
		videoSurface.setLayoutParams(params);
		videoSurface.invalidate();
	}

	/**
	 * 更新分页选择滑动条
	 * 
	 * @return void
	 * @throws
	 */
	public void refreshTabView() {
		ruleSeriesItemAdapter.notifyDataSetChanged();
		ruleSeriesPagerGrid.setNumColumns(seriesRst.cntsList.size());
		// width是否也需要取余
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				(int) (ScreenUtil.dp2px(78) * seriesRst.cntsList.size()),
				ScreenUtil.dp2px(50));
		ruleSeriesPagerGrid.setLayoutParams(params);
	}

	/**
	 * 更新缓存分页选择滑动条
	 * 
	 * @return void
	 * @throws
	 */
	public void refreshCacheTabView() {
		ruleGridSeriesCacheItemAdapter.notifyDataSetChanged();
		videoSeriesCachePager.setNumColumns(cacheRst.cntsList.size());
		// width是否也需要取余
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				(int) (ScreenUtil.dp2px(78) * cacheRst.cntsList.size()),
				ScreenUtil.dp2px(50));
		videoSeriesCachePager.setLayoutParams(params);
	}

	/**
	 * EventBus事件
	 * 
	 * @param msg
	 * @return void
	 * @throws
	 */
	public void onEvent(VideoPlayerMessage msg) {
		switch (msg.what) {
		case VideoPlayerMessage.MESSGAE_CHANGE_VIDEO:// 改变播放剧集
			ChangeVideoEvent event = (ChangeVideoEvent) msg.obj;
			if (playerAdapter != null && !event.isPlaying) {
				if (playerAdapter.isPlaying() && !playerAdapter.isAirOneMode()) {
					playerAdapter.stop();
					playerAdapter.release();
					videoSurface.setVisibility(View.INVISIBLE);
				}
				requestVideoPlayUrl(event.xyzPlayUrl, "1", true);
			}
			if (ruleSeriesItemAdapter != null) {
				ruleSeriesItemAdapter.setCurrentPlayUrl(event.xyzPlayUrl);
			}
			if (unRuleSeriesItemAdapter != null) {
				unRuleSeriesItemAdapter.setCurrentPlayUrl(event.xyzPlayUrl);
				unRuleSeriesItemAdapter.notifyDataSetChanged();
			}
			break;
		case VideoPlayerMessage.MESSGAE_CHANGE_FROM:// 改变播放来源
			break;
		case VideoPlayerMessage.MESSGAE_OPEN_RELEATED:// 打开相关视频
			LinkVideoEvent linkEvent = (LinkVideoEvent) msg.obj;
			if (playerAdapter != null) {
				switch (linkEvent.from) {
				case DETAILLINK:// 详情页关联视频点击过来的
					if (playerAdapter != null) {
						playerAdapter.stop();
						playerAdapter.release();
						videoSurface.setVisibility(View.INVISIBLE);
					}
					Intent intent = new Intent();
					intent.putExtra("from", LINK_VIDEO);
					intent.putExtra("action", PlayerAction.DETAIL.name());
					intent.putExtra("name", linkEvent.name);
					intent.putExtra("vgdetail", linkEvent.vgdetail);
					handNewIntent(intent);
					break;
				case FULLLINK:// 全屏页关联视频点击过来的
				case LOCALLINK:// 本地关联视频点击过来的
					// 这两个暂时放一块处理
					boolean isAirone;
					if (playerAdapter != null) {
						isAirone = playerAdapter.isAirOneMode();
						if (isAirone) {
							// airone模式
							// 先请求视频详情
							openFrom = LINK_VIDEO;
							requestVideoDetail(linkEvent.vgdetail);
						} else {
							Intent intent2 = new Intent();
							intent2.putExtra("from", LINK_VIDEO);
							if (TextUtils.isEmpty(linkEvent.vgdetail)) {
								intent2.putExtra("action",
										PlayerAction.FULLPLAY.name());
								intent2.putExtra("xyzplay", linkEvent.xyzplay);
							} else {
								intent2.putExtra("action",
										PlayerAction.DETAIL.name());
								intent2.putExtra("vgdetail", linkEvent.vgdetail);
							}
							intent2.putExtra("name", linkEvent.name);
							handNewIntent(intent2);
						}
					}
					break;
				default:
					break;
				}
			}
		case VideoPlayerMessage.MESSGAE_HEADSETPLUG_OUT:// 耳机拔出了，暂停视频，并且显示暂停界面
		case VideoPlayerMessage.MESSGAE_SCREEN_OFF:// 屏幕熄灭了，暂停视频，并且显示暂停界面
			if (playerAdapter != null && playerAdapter.isPlaying()) {
				if (playerAdapter.isLiveVideo()) {
					playerAdapter.stop();
					playerAdapter.release();
					btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
					btPlayFull
							.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
				} else {
					playerAdapter.pause();
					btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
					btPlayFull
							.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
				}
				if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
					showFullScreenLayout();
				} else {
					showOrHideSmallControlView(true);
				}
			}
			break;
		case VideoPlayerMessage.MESSGAE_SDCARD_EJECT:// sd卡拔出了
			if (playerAdapter != null && playerAdapter.isPlaying()) {
				playerAdapter.stop();
				playerAdapter.release();
				playerAdapter.updatePlayRecord2MediaInfo();
				btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
				btPlayFull
						.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
			}
			break;
		case VideoPlayerMessage.MESSGAE_CALL_STATE_RINGING:// 来电响铃了
			if (playerAdapter != null && playerAdapter.isPlaying()) {
				if (playerAdapter.isLiveVideo()) {
					playerAdapter.stop();
					playerAdapter.release();
					btPlay.setBackgroundResource(R.drawable.video_detail_play_selector);
					btPlayFull
							.setBackgroundResource(R.drawable.video_fullscreen_play_selector);
				} else {
					playerAdapter.pause();
				}
			}
			break;
		case VideoPlayerMessage.MESSGAE_USER_PRESENT:// 解锁了
			if (playerAdapter != null && !playerAdapter.isPlaying() && !stop) {
				playerAdapter.play();
			}
			break;
		case StorageModule.MSG_ADD_CACHE_SUCCESS:
			// 添加离线缓存任务成功回调,在这里关闭进度条
			L.v(TAG, "add cache success !");
			L.v(TAG, "add cache success !" + System.currentTimeMillis());
			if (isAddingCache) {
				isAddingCache = false;
				mHandler.postDelayed(new Runnable() {
					@Override
					public void run() {
						addCacheSuccess();
					}
				}, 1000);
			}
			break;
		case StorageModule.MSG_ADD_CACHE_FAIL:
			// 添加离线缓存任务成功回调,在这里关闭进度条
			L.v(TAG, "add cache fail !");
			L.v(TAG, "add cache fail !" + System.currentTimeMillis());
			if (isAddingCache) {
				isAddingCache = false;
				mHandler.postDelayed(new Runnable() {
					@Override
					public void run() {
						addCacheSuccess();
					}
				}, 1000);
			}
			break;
		default:
			break;
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
		isCancel = true;
		// if (playerAdapter != null && playerAdapter.isPlaying() &&
		// !playerAdapter.isAirOneMode()) {
		// playerAdapter.pause();
		// }
	}

	/**
	 * 添加收藏操作
	 * 
	 * @param furl
	 * @return void
	 * @throws
	 */

	private void doCollection(String furl, boolean isToast) {
		// 添加数据到数据库 封装data数据 发送请求
		L.v("测试", "详情页:doCollection------------------>" + furl);
		// 截取furl中的数据
		String cid = "";
		String ccid = "";
		String videoid = "";
		String clid = "";

		String stringlist[] = furl.substring(furl.indexOf("?") + 1).split("&");
		for (int i = 0; i < stringlist.length; i++) {
			// L.v("测试", "截取:" + stringlist[i]);
			if (stringlist[i].startsWith("cid=")) {
				cid = stringlist[i].substring(stringlist[i].indexOf("=") + 1);
			}
			if (stringlist[i].startsWith("ccid=")) {
				ccid = stringlist[i].substring(stringlist[i].indexOf("=") + 1);
			}
			if (stringlist[i].startsWith("videoid=")) {
				videoid = stringlist[i]
						.substring(stringlist[i].indexOf("=") + 1);
			}
			if (stringlist[i].startsWith("clid=")) {
				clid = stringlist[i].substring(stringlist[i].indexOf("=") + 1);
			}
		}

		List<RecordData> updateInfo = new ArrayList<RecordData>();
		RecordData data = new RecordData();
		if ("" != ccid) {
			data.ccid = Integer.valueOf(ccid);
		} else {
			data.ccid = 0;
		}
		if ("" != cid) {
			data.cid = Integer.valueOf(cid);
		} else {
			data.cid = 0;
		}
		if ("" != videoid) {
			data.videoid = Integer.valueOf(videoid);
		} else {
			data.videoid = 0;
		}
		if ("" != clid) {
			data.clid = Integer.valueOf(clid);
		} else {
			data.clid = 0;
		}

		if (playerAdapter.getVideoDetail().fstate == 1) {// 已经收藏
			data.type = 2;
		} else {// 未收藏
			data.type = 1;
		}
		data.tp = 99999;
		// 上报添加收藏位置
		data.ifp = 1;

		String time = System.currentTimeMillis() + "";
		time = time.substring(5);
		data.updatetime = Integer.valueOf(time);

		updateInfo.add(data);
		// 添加记录到数据库 type=1 提示用户收藏成功

		long fromid = playerAdapter.getVideoDetail().furl.fromid;
		Froms formList = playerAdapter.getVideoDetail().froms;

		// 获取来源信息
		From from = null;
		for (int i = 0; i < formList.fromList.size(); i++) {
			if (formList.fromList.get(i).fromid == fromid) {
				from = formList.fromList.get(i);
			}
		}

		// 离线添加数据到数据库.
		OfflineCache offlineCache = new OfflineCache();
		offlineCache.setCacheCCID(data.ccid);
		offlineCache.setCacheCID(data.cid);
		offlineCache.setCacheCLID(data.clid);
		offlineCache.setCacheVideoId(data.videoid);
		offlineCache.setCacheName(playerAdapter.getVideoDetail().name);
		offlineCache.setCacheImageUrl(playerAdapter.getShost()
				+ FoneUtil.formatUrl(playerAdapter.getVideoDetail().pic));
		offlineCache.setCacheIsDelete(false);
		offlineCache.setCacheIsDownlaod(false);
		offlineCache.setCacheReportPage(1);
		offlineCache.setCacheCreateTime(Integer.valueOf(time));
		if (playerAdapter.getVideoDetail().fstate == 1) {// 已经收藏

			offlineCache
					.setCacheSynchronzieType(OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_DELETE_WAIT);
		} else {// 未收藏
			offlineCache
					.setCacheSynchronzieType(OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_ADD_WAIT);
		}
		if (null != from) {
			offlineCache.setCacheContentType(from.favtyp);
			offlineCache.setCacheXYZPlayUrl(from.defaulturl);
			offlineCache.setCacheIsDownloadable(from.btndown == 0 ? false
					: true);
			offlineCache.setCacheIsVip(from.ftv == 1 ? true : false);// 视频Vip信息
			if (from.favtyp == OfflineCache.CACHE_CONTENT_TYPE_ANIMATION
					|| from.favtyp == OfflineCache.CACHE_CONTENT_TYPE_TV
					|| from.favtyp == OfflineCache.CACHE_CONTENT_TYPE_VARIETY) {
				offlineCache
						.setCacheDetailUrl(playerAdapter.getVideoDetail().vgurl);
				offlineCache
						.setCacheDramaUrl(playerAdapter.getVideoDetail().vgurl);
				offlineCache.setCacheEpisodeUpdateInfo(from.updateDesc);
			} else {
				offlineCache
						.setCacheDetailUrl(playerAdapter.getVideoDetail().vgurl);
				offlineCache
						.setCacheDramaUrl(playerAdapter.getVideoDetail().vgurl);
				offlineCache.setCacheEpisodeUpdateInfo("");
			}
		}

		L.v(TAG, "doCollection", "添加收藏的offlineCache" + offlineCache.toString());
		// 发送添加收藏请求

		if (UserInfoManager.isLogin()) {
			if (FoneUtil.isNetOk(mContext)) {
				// 发送收藏请求 根据请求处理同步状态
				AddCollectionCallback collectionCallback = new AddCollectionCallback();
				collectionCallback.setOfflineCache(offlineCache);
				if (playerAdapter.getVideoDetail().fstate == 1) {// 已经收藏 执行取消收藏
					if (isToast) {
						FoneUtil.showToast(mContext, "取消收藏成功");
					}
					playerAdapter.getVideoDetail().fstate = 0;
					Request.getInstance().collection(updateInfo, 2, 1, 0, 0,
							collectionCallback);

					StorageModule.getInstance().deleteFavourite(offlineCache);
				} else {// 未收藏 执行添加收藏
					if (isToast) {
						FoneUtil.showToast(mContext, "已加入到收藏");
					}
					playerAdapter.getVideoDetail().fstate = 1;
					Request.getInstance().collection(updateInfo, 1, 1, 0, 0,
							collectionCallback);

					StorageModule.getInstance().addFavourite(offlineCache);
				}
				updateCollectionIcon();
			} else {
				// 保存本地数据 状态为未同步 修改图标选中状态
				doLocalCollection(offlineCache, isToast);
			}
		} else {
			// 直接操作本地数据库 状态均为未同步
			doLocalCollection(offlineCache, isToast);
		}

		L.v("测试",
				"添加数据库以后 数据中的数据:"
						+ StorageModule
								.getInstance()
								.getFavouriteList(
										OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_CLIENT_ALL));

	}

	/**
	 * 执行本地收藏操作(数据库)
	 * 
	 * @param offlineCache
	 * @return void
	 * @throws
	 */
	private void doLocalCollection(OfflineCache offlineCache, boolean isToast) {
		if (UserInfoManager.isLogin()) {
			if (playerAdapter.getVideoDetail().fstate == 1) {// 已经收藏 执行取消收藏
				if (isToast) {
					FoneUtil.showToast(mContext, "取消收藏成功");
				}
				playerAdapter.getVideoDetail().fstate = 0;
				offlineCache
						.setCacheSynchronzieType(OfflineCache.CACHE_FAVOURITE_SYNCHRONZIE_DELETE_WAIT);
				StorageModule.getInstance().updateFavouriteSynchronzieType(
						offlineCache);
			} else {// 未收藏 执行添加收藏
				if (isToast) {
					FoneUtil.showToast(mContext, "已加入到收藏");
				}
				playerAdapter.getVideoDetail().fstate = 1;
				StorageModule.getInstance().addFavourite(offlineCache);
			}
		} else {
			if (playerAdapter.getVideoDetail().fstate == 1) {// 已经收藏 执行取消收藏
				if (isToast) {
					FoneUtil.showToast(mContext, "取消收藏成功");
				}
				playerAdapter.getVideoDetail().fstate = 0;
				StorageModule.getInstance().deleteFavourite(offlineCache);
			} else {// 未收藏 执行添加收藏
				if (isToast) {
					FoneUtil.showToast(mContext, "已加入到收藏");
				}
				playerAdapter.getVideoDetail().fstate = 1;
				StorageModule.getInstance().addFavourite(offlineCache);
			}
		}
		updateCollectionIcon();
	}

	private class AddCollectionCallback implements
			com.fone.player.client.Callback<CollectionRst> {
		private OfflineCache offlineCache;

		public void setOfflineCache(OfflineCache offlineCache) {

			this.offlineCache = offlineCache;
		}

		@Override
		public void onSuccess(CollectionRst t) {
			if (t.result == 0) {
				// FoneUtil.showToast(mContext, "测试用:云端收藏数据修改成功,本地也成功");
				L.v("测试", "修改收藏结果" + t.toString());
				// 修改对应 videoId的type数值 1->0
				offlineCache.setCacheSynchronzieType(0);
				StorageModule.getInstance().updateFavouriteSynchronzieType(
						offlineCache);
			} else {
				FoneUtil.showToast(mContext, "同步失败，该视频未同步到云端");
				Reporter.logError(offlineCache.getCacheCID() + "", 4);
			}
		}

		@Override
		public void onFailure(Error error) {
			L.v(TAG, "AddCollectionCallback onFailure", "isNetworkError : "
					+ error.isNetworkError() + " status : " + error.getStatus()
					+ " reason : " + error.getReason());
			FoneUtil.showToast(mContext, "同步失败，该视频未同步到云端");
			Reporter.logError(offlineCache.getCacheCID() + "", 4);
		}

	}

	@Override
	public void finish() {
		stop = true;
		if (openFrom == NOTIFICATION_EXTERNAL || openFrom == NOTIFY_COLLECTION) {
			// 要打开应用
			if (ActivityQueue.getSize() <= 1) {
				Intent i = new Intent(FonePlayerActivity.this,
						SplashActivity.class);
				startActivity(i);
			}
		}
		super.finish();
	}

	/**
	 * 更新收藏图标
	 * 
	 * @return void
	 * @throws
	 */
	private void updateCollectionIcon() {
		L.v("测试", "收藏状态");
		if (playerAdapter.getVideoDetail().fstate == 0) {// 未收藏
			playerCollection
					.setBackgroundResource(R.drawable.video_detail_collection_selector);
		} else {// 已收藏
			playerCollection
					.setBackgroundResource(R.drawable.video_detail_collection_selector_su);
		}
	}

	/**
	 * 初始化版本升级
	 * 
	 * @return void
	 */
	private void initUpdate() {

		isCancel = false;
		L.v("测试", "升级走了:initUpdate()");
		if (null != FoneConstant.loginRst) {
			L.v("测试",
					"FoneConstant.loginRst非空 "
							+ FoneConstant.loginRst.toString());
			LoginRst rst = FoneConstant.loginRst;

			if (null != rst.softupdate) {
				if (action != PlayerAction.FULLPLAY) {
					L.v("测试", "详情页");
					// if (FoneConstant.UPDATE_DETAIL ==
					// rst.softupdate.position && FoneConstant.isUpdate ==
					// false) {
					// L.v("测试", "详情页升级校验");
					// startUpdateDialogTimer(rst);
					// }
					if (getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE) {
						if (FoneConstant.UPDATE_FULLSCREEN == rst.softupdate.position
								&& FoneConstant.isUpdate == false) {
							L.v("测试", "详情页升级校验==横屏");
							startUpdateDialogTimer(rst);
						}
					} else {
						if (FoneConstant.UPDATE_DETAIL == rst.softupdate.position
								&& FoneConstant.isUpdate == false) {
							L.v("测试", "详情页升级校验 ==竖屏");
							startUpdateDialogTimer(rst);
						}
					}
				} else {
					L.v("测试", "全屏");
					if (FoneConstant.UPDATE_FULLSCREEN == rst.softupdate.position
							&& FoneConstant.isUpdate == false) {
						L.v("测试", "全屏页升级校验");
						startUpdateDialogTimer(rst);
					}
				}
			}

		} else {
			L.v("测试", "FoneConstant.loginRst空,升级不执行");
		}

	}

	private void startUpdateDialogTimer(final LoginRst rst) {

		if (FoneConstant.FORCE_UPDATE.equals(rst.softupdate.updateflag)) {
			isTimeing = true;
			new UpdateDialog(mContext, FonePlayerActivity.this,
					rst.softupdate.updatedesc, UpdateDialog.FORCE, rst);
		} else {
			// 如果该次时间差超过预定时间,弹框 否则不弹
			if ((System.currentTimeMillis() - SharedPreferenceModule
					.getInstance().getLong(FoneConstant.LAST_UPDATA_TIME_SP, 0)) < rst.softupdate.hitday
					* 24 * 60 * 60 * 1000) {
				isTimeing = true;
				return;
			}
			int time = 0;
			if (!"".equals(rst.softupdate.t)) {
				if (null != rst.softupdate && null != rst.softupdate.t)
					time = Integer.valueOf(rst.softupdate.t);
				L.v("测试", "延时时间:" + time);
			}
			final int runnableTime = time;
			final long firstTime = System.currentTimeMillis();
			new Thread(new Runnable() {
				@Override
				public void run() {
					isTimeing = true;
					while (true) {
						if (System.currentTimeMillis() == firstTime
								+ runnableTime * 1000) {
							L.v("测试", "到时间! 发消息 中断");
							if (mHandler == null) {
								return;
							} else {
								Message message = mHandler
										.obtainMessage(SHOW_UPDATE_DAILOG);
								message.obj = rst;
								mHandler.sendMessage(message);
							}
							isTimeing = false;
							break;
						}
						if (isCancel) {
							L.v("测试", "取消 中断");
							isTimeing = false;
							break;
						}
						// L.v("测试", "等待");

					}

				}
			}).start();

		}
	}

	public VgdetailRst getVgdetailRst() {
		return playerAdapter.getVideoDetail();
	}

	public boolean isBuffering() {
		return buffering;
	}

}
